Skip to content

Commit

Permalink
Merge pull request #390 from eed3si9n/wip/configref
Browse files Browse the repository at this point in the history
intern/flyweight ConfigRef
  • Loading branch information
eed3si9n authored Nov 21, 2021
2 parents 3ca1898 + 129b43a commit cb41524
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 83 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
trait LibraryManagementCodec extends sjsonnew.BasicJsonProtocol
with sbt.librarymanagement.ConfigRefFormats
trait LibraryManagementCodec extends sbt.librarymanagement.ConfigRefFormats
with sjsonnew.BasicJsonProtocol
with sbt.librarymanagement.RetrieveConfigurationFormats
with sbt.librarymanagement.UpdateLoggingFormats
with sbt.internal.librarymanagement.formats.LogicalClockFormats
Expand Down
18 changes: 0 additions & 18 deletions core/src/main/contraband/librarymanagement.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,24 +192,6 @@
],
"toString": "s\"$caller\""
},
{
"name": "ConfigRef",
"namespace": "sbt.librarymanagement",
"target": "Scala",
"type": "record",
"doc": [
"A reference to Configuration."
],
"fields": [
{
"name": "name",
"type": "String",
"doc": [ "The name of the configuration that eventually get used by Maven." ]
}
],
"parentsCompanion": "sbt.librarymanagement.ConfigRefFunctions",
"toString": "name"
},
{
"name": "ConfigurationReport",
"namespace": "sbt.librarymanagement",
Expand Down
75 changes: 75 additions & 0 deletions core/src/main/scala/sbt/librarymanagement/ConfigRef.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* This code is generated using [[https://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
package sbt.librarymanagement

import scala.collection.concurrent.TrieMap

/**
* A reference to Configuration.
* @param name The name of the configuration that eventually get used by Maven.
*/
final class ConfigRef private (val name: String) extends Serializable {

override def equals(o: Any): Boolean =
this.eq(o.asInstanceOf[AnyRef])

override val hashCode: Int = {
37 * (37 * (17 + "sbt.librarymanagement.ConfigRef".##) + name.##)
}

override def toString: String = {
name
}

private[this] def copy(name: String = name): ConfigRef = {
ConfigRef(name)
}

def withName(name: String): ConfigRef = {
copy(name = name)
}
}

object ConfigRef extends sbt.librarymanagement.ConfigRefFunctions {
// cache the reference to ConfigRefs
private val cache = new TrieMap[String, ConfigRef]
private lazy val Default = new ConfigRef("default")
private lazy val Compile = new ConfigRef("compile")
private lazy val IntegrationTest = new ConfigRef("it")
private lazy val Provided = new ConfigRef("provided")
private lazy val Runtime = new ConfigRef("runtime")
private lazy val Test = new ConfigRef("test")
private lazy val System = new ConfigRef("system")
private lazy val Optional = new ConfigRef("optional")
private lazy val Pom = new ConfigRef("pom")
private lazy val ScalaTool = new ConfigRef("scala-tool")
private lazy val ScalaDocTool = new ConfigRef("scala-doc-tool")
private lazy val CompilerPlugin = new ConfigRef("plugin")
private lazy val Component = new ConfigRef("component")
private lazy val RuntimeInternal = new ConfigRef("runtime-internal")
private lazy val TestInternal = new ConfigRef("test-internal")
private lazy val IntegrationTestInternal = new ConfigRef("it-internal")
private lazy val CompileInternal = new ConfigRef("compile-internal")

def apply(name: String): ConfigRef = name match {
case "default" => Default
case "compile" => Compile
case "it" => IntegrationTest
case "provided" => Provided
case "runtime" => Runtime
case "test" => Test
case "system" => System
case "optional" => Optional
case "pom" => Pom
case "scala-tool" => ScalaTool
case "scala-doc-tool" => ScalaDocTool
case "plugin" => CompilerPlugin
case "component" => Component
case "runtime-internal" => RuntimeInternal
case "test-internal" => TestInternal
case "it-internal" => IntegrationTestInternal
case "compile-internal" => CompileInternal
case _ => cache.getOrElseUpdate(name, new ConfigRef(name))
}
}
31 changes: 31 additions & 0 deletions core/src/main/scala/sbt/librarymanagement/ConfigRefFormats.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This code is generated using [[https://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
package sbt.librarymanagement

import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }

trait ConfigRefFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val ConfigRefFormat: JsonFormat[sbt.librarymanagement.ConfigRef] =
new JsonFormat[sbt.librarymanagement.ConfigRef] {
override def read[J](
__jsOpt: Option[J],
unbuilder: Unbuilder[J]
): sbt.librarymanagement.ConfigRef = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val name = unbuilder.readField[String]("name")
unbuilder.endObject()
sbt.librarymanagement.ConfigRef(name)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.librarymanagement.ConfigRef, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("name", obj.name)
builder.endObject()
}
}
}
4 changes: 4 additions & 0 deletions project/DatatypeConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ object DatatypeConfig {
Nil
}

case "sbt.librarymanagement.ConfigRef" => { _ =>
"sbt.librarymanagement.ConfigRefFormats" :: Nil
}

// TODO: These are handled by BasicJsonProtocol, and sbt-datatype should handle them by default, imo
case "Option" | "Set" | "scala.Vector" => { tpe =>
getFormats(oneArg(tpe))
Expand Down

0 comments on commit cb41524

Please sign in to comment.