Skip to content

Commit

Permalink
Use Vector[String] instead of Option[String] in ModuleID
Browse files Browse the repository at this point in the history
  • Loading branch information
Duhemm committed Jul 11, 2017
1 parent 6be7ffe commit 460d4d7
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class ModuleID private (
val organization: String,
val name: String,
val revision: String,
val configurations: Option[String],
val configurations: Vector[String],
val isChanging: Boolean,
val isTransitive: Boolean,
val isForce: Boolean,
Expand All @@ -19,7 +19,7 @@ final class ModuleID private (
val crossVersion: sbt.librarymanagement.CrossVersion,
val branchName: Option[String]) extends sbt.librarymanagement.ModuleIDExtra with Serializable {

private def this(organization: String, name: String, revision: String) = this(organization, name, revision, None, false, true, false, Vector.empty, Vector.empty, Vector.empty, Map.empty, sbt.librarymanagement.Disabled(), None)
private def this(organization: String, name: String, revision: String) = this(organization, name, revision, scala.collection.immutable.Vector("compile"), false, true, false, Vector.empty, Vector.empty, Vector.empty, Map.empty, sbt.librarymanagement.Disabled(), None)

override def equals(o: Any): Boolean = o match {
case x: ModuleID => (this.organization == x.organization) && (this.name == x.name) && (this.revision == x.revision) && (this.configurations == x.configurations) && (this.isChanging == x.isChanging) && (this.isTransitive == x.isTransitive) && (this.isForce == x.isForce) && (this.explicitArtifacts == x.explicitArtifacts) && (this.inclusions == x.inclusions) && (this.exclusions == x.exclusions) && (this.extraAttributes == x.extraAttributes) && (this.crossVersion == x.crossVersion) && (this.branchName == x.branchName)
Expand All @@ -31,7 +31,7 @@ final class ModuleID private (
override def toString: String = {
this.toStringImpl
}
protected[this] def copy(organization: String = organization, name: String = name, revision: String = revision, configurations: Option[String] = configurations, isChanging: Boolean = isChanging, isTransitive: Boolean = isTransitive, isForce: Boolean = isForce, explicitArtifacts: Vector[sbt.librarymanagement.Artifact] = explicitArtifacts, inclusions: Vector[sbt.librarymanagement.InclExclRule] = inclusions, exclusions: Vector[sbt.librarymanagement.InclExclRule] = exclusions, extraAttributes: Map[String, String] = extraAttributes, crossVersion: sbt.librarymanagement.CrossVersion = crossVersion, branchName: Option[String] = branchName): ModuleID = {
protected[this] def copy(organization: String = organization, name: String = name, revision: String = revision, configurations: Vector[String] = configurations, isChanging: Boolean = isChanging, isTransitive: Boolean = isTransitive, isForce: Boolean = isForce, explicitArtifacts: Vector[sbt.librarymanagement.Artifact] = explicitArtifacts, inclusions: Vector[sbt.librarymanagement.InclExclRule] = inclusions, exclusions: Vector[sbt.librarymanagement.InclExclRule] = exclusions, extraAttributes: Map[String, String] = extraAttributes, crossVersion: sbt.librarymanagement.CrossVersion = crossVersion, branchName: Option[String] = branchName): ModuleID = {
new ModuleID(organization, name, revision, configurations, isChanging, isTransitive, isForce, explicitArtifacts, inclusions, exclusions, extraAttributes, crossVersion, branchName)
}
def withOrganization(organization: String): ModuleID = {
Expand All @@ -43,7 +43,7 @@ final class ModuleID private (
def withRevision(revision: String): ModuleID = {
copy(revision = revision)
}
def withConfigurations(configurations: Option[String]): ModuleID = {
def withConfigurations(configurations: Vector[String]): ModuleID = {
copy(configurations = configurations)
}
def withIsChanging(isChanging: Boolean): ModuleID = {
Expand Down Expand Up @@ -76,6 +76,6 @@ final class ModuleID private (
}
object ModuleID extends sbt.librarymanagement.ModuleIDFunctions {

def apply(organization: String, name: String, revision: String): ModuleID = new ModuleID(organization, name, revision, None, false, true, false, Vector.empty, Vector.empty, Vector.empty, Map.empty, sbt.librarymanagement.Disabled(), None)
def apply(organization: String, name: String, revision: String, configurations: Option[String], isChanging: Boolean, isTransitive: Boolean, isForce: Boolean, explicitArtifacts: Vector[sbt.librarymanagement.Artifact], inclusions: Vector[sbt.librarymanagement.InclExclRule], exclusions: Vector[sbt.librarymanagement.InclExclRule], extraAttributes: Map[String, String], crossVersion: sbt.librarymanagement.CrossVersion, branchName: Option[String]): ModuleID = new ModuleID(organization, name, revision, configurations, isChanging, isTransitive, isForce, explicitArtifacts, inclusions, exclusions, extraAttributes, crossVersion, branchName)
def apply(organization: String, name: String, revision: String): ModuleID = new ModuleID(organization, name, revision, scala.collection.immutable.Vector("compile"), false, true, false, Vector.empty, Vector.empty, Vector.empty, Map.empty, sbt.librarymanagement.Disabled(), None)
def apply(organization: String, name: String, revision: String, configurations: Vector[String], isChanging: Boolean, isTransitive: Boolean, isForce: Boolean, explicitArtifacts: Vector[sbt.librarymanagement.Artifact], inclusions: Vector[sbt.librarymanagement.InclExclRule], exclusions: Vector[sbt.librarymanagement.InclExclRule], extraAttributes: Map[String, String], crossVersion: sbt.librarymanagement.CrossVersion, branchName: Option[String]): ModuleID = new ModuleID(organization, name, revision, configurations, isChanging, isTransitive, isForce, explicitArtifacts, inclusions, exclusions, extraAttributes, crossVersion, branchName)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ implicit lazy val ModuleIDFormat: JsonFormat[sbt.librarymanagement.ModuleID] = n
val organization = unbuilder.readField[String]("organization")
val name = unbuilder.readField[String]("name")
val revision = unbuilder.readField[String]("revision")
val configurations = unbuilder.readField[Option[String]]("configurations")
val configurations = unbuilder.readField[Vector[String]]("configurations")
val isChanging = unbuilder.readField[Boolean]("isChanging")
val isTransitive = unbuilder.readField[Boolean]("isTransitive")
val isForce = unbuilder.readField[Boolean]("isForce")
Expand Down
26 changes: 13 additions & 13 deletions core/src/main/contraband/librarymanagement.json
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,19 @@
"type": "record",
"parents": "sbt.librarymanagement.ModuleIDExtra",
"fields": [
{ "name": "organization", "type": "String" },
{ "name": "name", "type": "String" },
{ "name": "revision", "type": "String" },
{ "name": "configurations", "type": "Option[String]", "default": "None", "since": "0.0.1" },
{ "name": "isChanging", "type": "boolean", "default": "false", "since": "0.0.1" },
{ "name": "isTransitive", "type": "boolean", "default": "true", "since": "0.0.1" },
{ "name": "isForce", "type": "boolean", "default": "false", "since": "0.0.1" },
{ "name": "explicitArtifacts", "type": "sbt.librarymanagement.Artifact*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "inclusions", "type": "sbt.librarymanagement.InclExclRule*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "exclusions", "type": "sbt.librarymanagement.InclExclRule*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "extraAttributes", "type": "Map[String, String]", "default": "Map.empty", "since": "0.0.1" },
{ "name": "crossVersion", "type": "sbt.librarymanagement.CrossVersion", "default": "sbt.librarymanagement.Disabled()", "since": "0.0.1" },
{ "name": "branchName", "type": "Option[String]", "default": "None", "since": "0.0.1" }
{ "name": "organization", "type": "String" },
{ "name": "name", "type": "String" },
{ "name": "revision", "type": "String" },
{ "name": "configurations", "type": "String*", "default": "scala.collection.immutable.Vector(\"compile\")", "since": "0.0.1" },
{ "name": "isChanging", "type": "boolean", "default": "false", "since": "0.0.1" },
{ "name": "isTransitive", "type": "boolean", "default": "true", "since": "0.0.1" },
{ "name": "isForce", "type": "boolean", "default": "false", "since": "0.0.1" },
{ "name": "explicitArtifacts", "type": "sbt.librarymanagement.Artifact*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "inclusions", "type": "sbt.librarymanagement.InclExclRule*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "exclusions", "type": "sbt.librarymanagement.InclExclRule*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "extraAttributes", "type": "Map[String, String]", "default": "Map.empty", "since": "0.0.1" },
{ "name": "crossVersion", "type": "sbt.librarymanagement.CrossVersion", "default": "sbt.librarymanagement.Disabled()", "since": "0.0.1" },
{ "name": "branchName", "type": "Option[String]", "default": "None", "since": "0.0.1" }
],
"toString": [
"this.toStringImpl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ private[sbt] object CompatibilityWarning {
log: Logger
): Unit = {
val monitoredConfigsStr: Set[String] = (config.configurations map { _.name }).toSet
def inMonitoredConfigs(configOpt: Option[String]): Boolean =
configOpt match {
case Some(c) => (c.split(",").toSet intersect monitoredConfigsStr).nonEmpty
case None => monitoredConfigsStr contains "compile"
}
def inMonitoredConfigs(configs: Vector[String]): Boolean =
configs.toSet.intersect(monitoredConfigsStr).nonEmpty
module.directDependencies foreach { m =>
if (!m.isTransitive && inMonitoredConfigs(m.configurations)) {
log.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import sbt.librarymanagement._

object UpdateClassifiersUtil {

def restrictedCopy(m: ModuleID, confs: Boolean) =
ModuleID(m.organization, m.name, m.revision)
def restrictedCopy(m: ModuleID, confs: Boolean) = {
val module = ModuleID(m.organization, m.name, m.revision)
.withCrossVersion(m.crossVersion)
.withExtraAttributes(m.extraAttributes)
.withConfigurations(if (confs) m.configurations else None)
.branch(m.branchName)
if (confs) module.withConfigurations(m.configurations)
else module
}

// This version adds explicit artifact
def classifiedArtifacts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ trait DependencyBuilders {
new RepositoryName(name)
}
final implicit def moduleIDConfigurable(m: ModuleID): ModuleIDConfigurable = {
require(m.configurations.isEmpty, "Configurations already specified for module " + m)
require(m.configurations.isEmpty || m.configurations == Vector("compile"),
"Configurations already specified for module " + m)
new ModuleIDConfigurable(m)
}
}
Expand All @@ -43,11 +44,16 @@ final class GroupArtifactID private[sbt] (
}
final class ModuleIDConfigurable private[sbt] (moduleID: ModuleID) {
def %(configuration: Configuration): ModuleID = %(configuration.name)
def %(configurations: Vector[String]) = {
val cleanConfigs = configurations.map(_.trim)
require(configurations.nonEmpty && configurations.forall(_.nonEmpty),
"Configurations cannot be empty.")
moduleID.withConfigurations(configurations = cleanConfigs)
}

def %(configurations: String): ModuleID = {
nonEmpty(configurations, "Configurations")
val c = configurations
moduleID.withConfigurations(configurations = Some(c))
val cs = configurations.split(",").toVector
%(cs)
}
}
final class RepositoryName private[sbt] (name: String) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/sbt/librarymanagement/ModuleIDExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class ModuleIDExtra {
def organization: String
def name: String
def revision: String
def configurations: Option[String]
def configurations: Vector[String]
def isChanging: Boolean
def isTransitive: Boolean
def isForce: Boolean
Expand All @@ -27,7 +27,7 @@ abstract class ModuleIDExtra {
organization: String = organization,
name: String = name,
revision: String = revision,
configurations: Option[String] = configurations,
configurations: Vector[String] = configurations,
isChanging: Boolean = isChanging,
isTransitive: Boolean = isTransitive,
isForce: Boolean = isForce,
Expand All @@ -41,7 +41,7 @@ abstract class ModuleIDExtra {

protected def toStringImpl: String =
s"""$organization:$name:$revision""" +
(configurations match { case Some(s) => ":" + s; case None => "" }) + {
configurations.mkString(":", "", "") + {
val attr = attributeString
if (attr == "") ""
else " " + attr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ object ScalaArtifacts {
if (isDotty)
Seq(
ModuleID(org, DottyIDPrefix, version)
.withConfigurations(Some(Configurations.ScalaTool.name + "->default(compile)"))
.withConfigurations(Vector(Configurations.ScalaTool.name + "->default(compile)"))
.withCrossVersion(CrossVersion.binary)
)
else
Expand All @@ -33,7 +33,7 @@ object ScalaArtifacts {

private[this] def scalaToolDependency(org: String, id: String, version: String): ModuleID =
ModuleID(org, id, version).withConfigurations(
Some(Configurations.ScalaTool.name + "->default,optional(default)")
Vector(Configurations.ScalaTool.name + "->default", "optional(default)")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class ConfigurationReportExtra {
val module = mr.module
if (module.configurations.isEmpty) {
val conf = mr.configurations map (c => s"$configuration->$c") mkString ";"
module.withConfigurations(Some(conf))
module.withConfigurations(Vector(conf))
} else module
}

Expand Down Expand Up @@ -135,9 +135,9 @@ abstract class UpdateReportExtra {
v reduceLeft { (agg, x) =>
agg.withConfigurations(
(agg.configurations, x.configurations) match {
case (None, _) => x.configurations
case (Some(ac), None) => Some(ac)
case (Some(ac), Some(xc)) => Some(s"$ac;$xc")
case (Vector("compile"), _) => x.configurations
case (ac, Vector("compile")) => ac
case (ac, xc) => ac ++ xc
}
)
}
Expand Down
8 changes: 4 additions & 4 deletions ivy/src/main/scala/sbt/internal/librarymanagement/Ivy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ private[sbt] object IvySbt {
val dds = moduleID.getDependencies
val deps = dds flatMap { dd =>
val module = toModuleID(dd.getDependencyRevisionId)
dd.getModuleConfigurations map (c => module.withConfigurations(Some(c)))
dd.getModuleConfigurations map (c => module.withConfigurations(Vector(c)))
}
inconsistentDuplicateWarning(deps)
}
Expand Down Expand Up @@ -812,10 +812,10 @@ private[sbt] object IvySbt {
def dependencyModuleId = dependency
}
dependency.configurations match {
case None => // The configuration for this dependency was not explicitly specified, so use the default
case Vector() => // The configuration for this dependency was not explicitly specified, so use the default
parser.parseDepsConfs(parser.getDefaultConf, dependencyDescriptor)
case Some(confs) => // The configuration mapping (looks like: test->default) was specified for this dependency
parser.parseDepsConfs(confs, dependencyDescriptor)
case confs => // The configuration mapping (looks like: test->default) was specified for this dependency
parser.parseDepsConfs(confs.mkString(","), dependencyDescriptor)
}
for (artifact <- dependency.explicitArtifacts) {
import artifact.{ name, `type`, extension, url }
Expand Down
2 changes: 1 addition & 1 deletion ivy/src/test/scala/BaseIvySpecification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ trait BaseIvySpecification extends UnitSpec {
def currentManaged: File = currentBase / "target" / "lib_managed"
def currentDependency: File = currentBase / "target" / "dependency"
def defaultModuleId: ModuleID =
ModuleID("com.example", "foo", "0.1.0").withConfigurations(Some("compile"))
ModuleID("com.example", "foo", "0.1.0").withConfigurations(Vector("compile"))

lazy val log = ConsoleLogger()
def lmEngine(uo: UpdateOptions = UpdateOptions()): LibraryManagement =
Expand Down
Loading

0 comments on commit 460d4d7

Please sign in to comment.