Skip to content

Commit

Permalink
Replace tuple with proper record type for licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
mdedetrich committed Sep 2, 2023
1 parent 689f347 commit 4c923e4
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ trait LibraryManagementCodec extends sbt.librarymanagement.ConfigRefFormats
with sbt.librarymanagement.SftpRepositoryFormats
with sbt.librarymanagement.ResolverFormats
with sbt.librarymanagement.ModuleConfigurationFormats
with sbt.librarymanagement.LicenseInfoFormats
with sbt.librarymanagement.ScmInfoFormats
with sbt.librarymanagement.ModuleInfoFormats
with sbt.librarymanagement.IvyFileConfigurationFormats
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* This code is generated using [[https://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
/** Basic license information for a project module */
final class LicenseInfo private (
val name: String,
val url: java.net.URL,
val distribution: Option[String],
val comments: Option[String]) extends Serializable {

private def this() = this("", new java.net.URL("http:"), None, None)

override def equals(o: Any): Boolean = this.eq(o.asInstanceOf[AnyRef]) || (o match {
case x: LicenseInfo => (this.name == x.name) && (this.url == x.url) && (this.distribution == x.distribution) && (this.comments == x.comments)
case _ => false
})
override def hashCode: Int = {
37 * (37 * (37 * (37 * (37 * (17 + "sbt.librarymanagement.LicenseInfo".##) + name.##) + url.##) + distribution.##) + comments.##)
}
override def toString: String = {
"LicenseInfo(" + name + ", " + url + ", " + distribution + ", " + comments + ")"
}
private[this] def copy(name: String = name, url: java.net.URL = url, distribution: Option[String] = distribution, comments: Option[String] = comments): LicenseInfo = {
new LicenseInfo(name, url, distribution, comments)
}
def withName(name: String): LicenseInfo = {
copy(name = name)
}
def withUrl(url: java.net.URL): LicenseInfo = {
copy(url = url)
}
def withDistribution(distribution: Option[String]): LicenseInfo = {
copy(distribution = distribution)
}
def withDistribution(distribution: String): LicenseInfo = {
copy(distribution = Option(distribution))
}
def withComments(comments: Option[String]): LicenseInfo = {
copy(comments = comments)
}
def withComments(comments: String): LicenseInfo = {
copy(comments = Option(comments))
}
}
object LicenseInfo {

def apply(): LicenseInfo = new LicenseInfo()
def apply(name: String, url: java.net.URL, distribution: Option[String], comments: Option[String]): LicenseInfo = new LicenseInfo(name, url, distribution, comments)
def apply(name: String, url: java.net.URL, distribution: String, comments: String): LicenseInfo = new LicenseInfo(name, url, Option(distribution), Option(comments))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* This code is generated using [[https://www.scala-sbt.org/contraband/ sbt-contraband]].
*/

// DO NOT EDIT MANUALLY
package sbt.librarymanagement
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait LicenseInfoFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val LicenseInfoFormat: JsonFormat[sbt.librarymanagement.LicenseInfo] = new JsonFormat[sbt.librarymanagement.LicenseInfo] {
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.librarymanagement.LicenseInfo = {
__jsOpt match {
case Some(__js) =>
unbuilder.beginObject(__js)
val name = unbuilder.readField[String]("name")
val url = unbuilder.readField[java.net.URL]("url")
val distribution = unbuilder.readField[Option[String]]("distribution")
val comments = unbuilder.readField[Option[String]]("comments")
unbuilder.endObject()
sbt.librarymanagement.LicenseInfo(name, url, distribution, comments)
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: sbt.librarymanagement.LicenseInfo, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("name", obj.name)
builder.addField("url", obj.url)
builder.addField("distribution", obj.distribution)
builder.addField("comments", obj.comments)
builder.endObject()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ final class ModuleInfo private (
val description: String,
val homepage: Option[java.net.URL],
val startYear: Option[Int],
val licenses: Vector[scala.Tuple2[String, java.net.URL]],
val licenses: Vector[sbt.librarymanagement.LicenseInfo],
val organizationName: String,
val organizationHomepage: Option[java.net.URL],
val scmInfo: Option[sbt.librarymanagement.ScmInfo],
val developers: Vector[sbt.librarymanagement.Developer]) extends Serializable {

private def this(nameFormal: String) = this(nameFormal, "", None, None, Vector.empty, "", None, None, Vector.empty)
private def this(nameFormal: String, description: String, homepage: Option[java.net.URL], startYear: Option[Int], organizationName: String, organizationHomepage: Option[java.net.URL], scmInfo: Option[sbt.librarymanagement.ScmInfo], developers: Vector[sbt.librarymanagement.Developer]) = this(nameFormal, description, homepage, startYear, Vector.empty, organizationName, organizationHomepage, scmInfo, developers)

override def equals(o: Any): Boolean = this.eq(o.asInstanceOf[AnyRef]) || (o match {
case x: ModuleInfo => (this.nameFormal == x.nameFormal) && (this.description == x.description) && (this.homepage == x.homepage) && (this.startYear == x.startYear) && (this.licenses == x.licenses) && (this.organizationName == x.organizationName) && (this.organizationHomepage == x.organizationHomepage) && (this.scmInfo == x.scmInfo) && (this.developers == x.developers)
Expand All @@ -28,7 +29,7 @@ final class ModuleInfo private (
override def toString: String = {
"ModuleInfo(" + nameFormal + ", " + description + ", " + homepage + ", " + startYear + ", " + licenses + ", " + organizationName + ", " + organizationHomepage + ", " + scmInfo + ", " + developers + ")"
}
private[this] def copy(nameFormal: String = nameFormal, description: String = description, homepage: Option[java.net.URL] = homepage, startYear: Option[Int] = startYear, licenses: Vector[scala.Tuple2[String, java.net.URL]] = licenses, organizationName: String = organizationName, organizationHomepage: Option[java.net.URL] = organizationHomepage, scmInfo: Option[sbt.librarymanagement.ScmInfo] = scmInfo, developers: Vector[sbt.librarymanagement.Developer] = developers): ModuleInfo = {
private[this] def copy(nameFormal: String = nameFormal, description: String = description, homepage: Option[java.net.URL] = homepage, startYear: Option[Int] = startYear, licenses: Vector[sbt.librarymanagement.LicenseInfo] = licenses, organizationName: String = organizationName, organizationHomepage: Option[java.net.URL] = organizationHomepage, scmInfo: Option[sbt.librarymanagement.ScmInfo] = scmInfo, developers: Vector[sbt.librarymanagement.Developer] = developers): ModuleInfo = {
new ModuleInfo(nameFormal, description, homepage, startYear, licenses, organizationName, organizationHomepage, scmInfo, developers)
}
def withNameFormal(nameFormal: String): ModuleInfo = {
Expand All @@ -43,7 +44,7 @@ final class ModuleInfo private (
def withStartYear(startYear: Option[Int]): ModuleInfo = {
copy(startYear = startYear)
}
def withLicenses(licenses: Vector[scala.Tuple2[String, java.net.URL]]): ModuleInfo = {
def withLicenses(licenses: Vector[sbt.librarymanagement.LicenseInfo]): ModuleInfo = {
copy(licenses = licenses)
}
def withOrganizationName(organizationName: String): ModuleInfo = {
Expand All @@ -62,5 +63,6 @@ final class ModuleInfo private (
object ModuleInfo {

def apply(nameFormal: String): ModuleInfo = new ModuleInfo(nameFormal)
def apply(nameFormal: String, description: String, homepage: Option[java.net.URL], startYear: Option[Int], licenses: Vector[scala.Tuple2[String, java.net.URL]], organizationName: String, organizationHomepage: Option[java.net.URL], scmInfo: Option[sbt.librarymanagement.ScmInfo], developers: Vector[sbt.librarymanagement.Developer]): ModuleInfo = new ModuleInfo(nameFormal, description, homepage, startYear, licenses, organizationName, organizationHomepage, scmInfo, developers)
def apply(nameFormal: String, description: String, homepage: Option[java.net.URL], startYear: Option[Int], organizationName: String, organizationHomepage: Option[java.net.URL], scmInfo: Option[sbt.librarymanagement.ScmInfo], developers: Vector[sbt.librarymanagement.Developer]): ModuleInfo = new ModuleInfo(nameFormal, description, homepage, startYear, organizationName, organizationHomepage, scmInfo, developers)
def apply(nameFormal: String, description: String, homepage: Option[java.net.URL], startYear: Option[Int], licenses: Vector[sbt.librarymanagement.LicenseInfo], organizationName: String, organizationHomepage: Option[java.net.URL], scmInfo: Option[sbt.librarymanagement.ScmInfo], developers: Vector[sbt.librarymanagement.Developer]): ModuleInfo = new ModuleInfo(nameFormal, description, homepage, startYear, licenses, organizationName, organizationHomepage, scmInfo, developers)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT MANUALLY
package sbt.librarymanagement
import _root_.sjsonnew.{ Unbuilder, Builder, JsonFormat, deserializationError }
trait ModuleInfoFormats { self: sbt.librarymanagement.ScmInfoFormats with sbt.librarymanagement.DeveloperFormats with sjsonnew.BasicJsonProtocol =>
trait ModuleInfoFormats { self: sbt.librarymanagement.LicenseInfoFormats with sbt.librarymanagement.ScmInfoFormats with sbt.librarymanagement.DeveloperFormats with sjsonnew.BasicJsonProtocol =>
implicit lazy val ModuleInfoFormat: JsonFormat[sbt.librarymanagement.ModuleInfo] = new JsonFormat[sbt.librarymanagement.ModuleInfo] {
override def read[J](__jsOpt: Option[J], unbuilder: Unbuilder[J]): sbt.librarymanagement.ModuleInfo = {
__jsOpt match {
Expand All @@ -15,7 +15,7 @@ implicit lazy val ModuleInfoFormat: JsonFormat[sbt.librarymanagement.ModuleInfo]
val description = unbuilder.readField[String]("description")
val homepage = unbuilder.readField[Option[java.net.URL]]("homepage")
val startYear = unbuilder.readField[Option[Int]]("startYear")
val licenses = unbuilder.readField[Vector[scala.Tuple2[String, java.net.URL]]]("licenses")
val licenses = unbuilder.readField[Vector[sbt.librarymanagement.LicenseInfo]]("licenses")
val organizationName = unbuilder.readField[String]("organizationName")
val organizationHomepage = unbuilder.readField[Option[java.net.URL]]("organizationHomepage")
val scmInfo = unbuilder.readField[Option[sbt.librarymanagement.ScmInfo]]("scmInfo")
Expand Down
17 changes: 15 additions & 2 deletions core/src/main/contraband/librarymanagement.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@
{ "name": "description", "type": "String", "default": "\"\"", "since": "0.0.1" },
{ "name": "homepage", "type": "Option[java.net.URL]", "default": "None", "since": "0.0.1" },
{ "name": "startYear", "type": "Option[Int]", "default": "None", "since": "0.0.1" },
{ "name": "licenses", "type": "scala.Tuple2[String, java.net.URL]*", "default": "Vector.empty", "since": "0.0.1" },
{ "name": "licenses", "type": "sbt.librarymanagement.LicenseInfo*", "default": "Vector.empty", "since": "2.0.0" },
{ "name": "organizationName", "type": "String", "default": "\"\"", "since": "0.0.1" },
{ "name": "organizationHomepage", "type": "Option[java.net.URL]", "default": "None", "since": "0.0.1" },
{ "name": "scmInfo", "type": "Option[sbt.librarymanagement.ScmInfo]", "default": "None", "since": "0.0.1" },
{ "name": "developers", "type": "sbt.librarymanagement.Developer*", "default": "Vector.empty", "since": "0.0.1" }
{ "name": "developers", "type": "sbt.librarymanagement.Developer*", "default": "Vector.empty", "since": "0.0.1" }
]
},
{
Expand Down Expand Up @@ -726,6 +726,19 @@
{ "name": "devConnection", "type": "String?", "default": "None", "since": "0.0.1" }
]
},
{
"name": "LicenseInfo",
"namespace": "sbt.librarymanagement",
"target": "Scala",
"type": "record",
"doc": "Basic license information for a project module",
"fields": [
{ "name": "name", "type": "String", "default": "\"\"", "since": "2.0.0" },
{ "name": "url", "type": "java.net.URL","default": "new java.net.URL(\"http:\")", "since": "2.0.0" },
{ "name": "distribution", "type": "String?", "default": "None", "since": "2.0.0" },
{ "name": "comments", "type": "String?", "default": "None", "since": "2.0.0" }
]
},
{
"name": "SshAuthentication",
"namespace": "sbt.librarymanagement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ final class IvySbt(
mod.setHomePage(h.toString)
}
moduleInfo.licenses foreach { l =>
mod.addLicense(new License(l._1, l._2.toString))
mod.addLicense(new License(l.name, l.url.toString))
}
IvySbt.addConfigurations(mod, configurations)
IvySbt.addArtifacts(mod, module.explicitArtifacts)
Expand Down

0 comments on commit 4c923e4

Please sign in to comment.