Cleanup Configuration

This commit is contained in:
Dale Wijnand 2018-03-08 14:37:10 +00:00
parent 127b90ee43
commit 8d49d5163c
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
1 changed files with 34 additions and 39 deletions

View File

@ -7,20 +7,17 @@ final class Configuration private[sbt] (
val name: String,
val description: String,
val isPublic: Boolean,
val extendsConfigs: Vector[sbt.librarymanagement.Configuration],
val transitive: Boolean)
extends sbt.librarymanagement.ConfigurationExtra
val extendsConfigs: Vector[Configuration],
val transitive: Boolean
) extends ConfigurationExtra
with Serializable {
require(name != null, "name cannot be null")
require(name.size > 0, "name cannot be empty")
require(name.nonEmpty, "name cannot be empty")
require(id != null, "id cannot be null")
require(id.size > 0, "id cannot be empty")
require(id.nonEmpty, "id cannot be empty")
require(id.head.isUpper, s"id must be capitalized: $id")
private def this(id: String, name: String) =
this(id, name, "", true, Vector.empty, true)
override def equals(o: Any): Boolean = o match {
case x: Configuration =>
(this.id == x.id) &&
@ -31,50 +28,48 @@ final class Configuration private[sbt] (
(this.transitive == x.transitive)
case _ => false
}
override val hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (37 * (17 + id.##) + name.##) + description.##) + isPublic.##) + extendsConfigs.##) + transitive.##)
}
override def toString: String = {
name
}
protected[this] def copy(id: String = id,
name: String = name,
description: String = description,
isPublic: Boolean = isPublic,
extendsConfigs: Vector[sbt.librarymanagement.Configuration] =
extendsConfigs,
transitive: Boolean = transitive): Configuration = {
override val hashCode: Int =
37 * (37 * (37 * (37 * (37 * (37 * (17 +
id.##) + name.##) + description.##) + isPublic.##) + extendsConfigs.##) + transitive.##)
override def toString: String = name
protected[this] def copy(
id: String = id,
name: String = name,
description: String = description,
isPublic: Boolean = isPublic,
extendsConfigs: Vector[Configuration] = extendsConfigs,
transitive: Boolean = transitive
): Configuration =
new Configuration(id, name, description, isPublic, extendsConfigs, transitive)
}
def withDescription(description: String): Configuration = {
copy(description = description)
}
def withDescription(description: String): Configuration = copy(description = description)
def withIsPublic(isPublic: Boolean): Configuration = {
copy(isPublic = isPublic)
}
def withIsPublic(isPublic: Boolean): Configuration = copy(isPublic = isPublic)
def withExtendsConfigs(
extendsConfigs: Vector[sbt.librarymanagement.Configuration]): Configuration = {
def withExtendsConfigs(extendsConfigs: Vector[Configuration]): Configuration =
copy(extendsConfigs = extendsConfigs)
}
def withTransitive(transitive: Boolean): Configuration = {
def withTransitive(transitive: Boolean): Configuration =
copy(transitive = transitive)
}
def toConfigRef: ConfigRef = ConfigRef(name)
}
object Configuration {
// Don't call this directly. It's intended to be used from config macro.
def of(id: String, name: String): Configuration =
new Configuration(id, name, "", true, Vector.empty, true)
def of(id: String,
name: String,
description: String,
isPublic: Boolean,
extendsConfigs: Vector[sbt.librarymanagement.Configuration],
transitive: Boolean): Configuration =
def of(
id: String,
name: String,
description: String,
isPublic: Boolean,
extendsConfigs: Vector[Configuration],
transitive: Boolean
): Configuration =
new Configuration(id, name, description, isPublic, extendsConfigs, transitive)
}