Skip to content

Commit

Permalink
Merge pull request #220 from alexarchambault/os-arch-indices
Browse files Browse the repository at this point in the history
Write per OS / architecture indices too
  • Loading branch information
alexarchambault authored Nov 1, 2023
2 parents 671cecb + 5900836 commit e2e245e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
23 changes: 19 additions & 4 deletions src/GenerateIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ object GenerateIndex {

def main(args: Array[String]): Unit = {

val output = "index.json"
val baseName = "index"

val dest = os.pwd / s"$baseName.json"

val correttoIndex0 = Corretto.fullIndex(GhToken.token)
val graalvmLegacyIndex0 = GraalvmLegacy.fullIndex(GhToken.token)
Expand All @@ -18,10 +20,23 @@ object GenerateIndex {
val zuluIndex0 = Zulu.index()
val libericaIndex0 = Liberica.index()

val json =
(graalvmLegacyIndex0 + graalvmIndex0 + oracleIndex0 + adoptIndex0 + zuluIndex0 + libericaIndex0 + correttoIndex0).json
val dest = os.Path(output, os.pwd)
val index = graalvmLegacyIndex0 +
graalvmIndex0 +
oracleIndex0 +
adoptIndex0 +
zuluIndex0 +
libericaIndex0 +
correttoIndex0

val json = index.json
os.write.over(dest, json)
System.err.println(s"Wrote $dest")

for (((os0, arch), osArchIndex) <- index.osArchIndices.toVector.sortBy(_._1)) {
val dest0 = os.pwd / s"$baseName-$os0-$arch.json"
val json0 = osArchIndex.json
os.write.over(dest0, json0)
System.err.println(s"Wrote $dest0")
}
}
}
48 changes: 29 additions & 19 deletions src/Index.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@ final case class Index(map: Map[String, Map[String, Map[String, Map[String, Stri
}
)

def +(other: Index): Index =
Index(Index.merge4(map, other.map))

def json: String =
Index.json4(map).render(indent = 2)

def osArchIndices: Map[(String, String), OsArchIndex] =
map.flatMap {
case (os, osMap) =>
osMap.map {
case (arch, osArchMap) =>
((os, arch), OsArchIndex(osArchMap))
}
}
}

object Index {
def empty: Index =
Index(Map.empty)
def apply(
os: String,
architecture: String,
jdkName: String,
jdkVersion: String,
url: String
): Index =
Index(Map(os -> Map(architecture -> Map(jdkName -> Map(jdkVersion -> url)))))

private def merge4(
a: Map[String, Map[String, Map[String, Map[String, String]]]],
b: Map[String, Map[String, Map[String, Map[String, String]]]]
Expand Down Expand Up @@ -98,9 +126,6 @@ final case class Index(map: Map[String, Map[String, Map[String, Map[String, Stri
}
.toMap

def +(other: Index): Index =
Index(merge4(map, other.map))

private def json4(
map: Map[String, Map[String, Map[String, Map[String, String]]]]
) = {
Expand Down Expand Up @@ -133,7 +158,7 @@ final case class Index(map: Map[String, Map[String, Map[String, Map[String, Stri
ujson.Obj(l.head, l.tail: _*)
}

private def json2(
def json2(
map: Map[String, Map[String, String]]
) = {
val l = map
Expand Down Expand Up @@ -165,19 +190,4 @@ final case class Index(map: Map[String, Map[String, Map[String, Map[String, Stri
ujson.Obj(l.head, l.tail: _*)
}

def json: String =
json4(map).render(indent = 2)
}

object Index {
def empty: Index =
Index(Map.empty)
def apply(
os: String,
architecture: String,
jdkName: String,
jdkVersion: String,
url: String
): Index =
Index(Map(os -> Map(architecture -> Map(jdkName -> Map(jdkVersion -> url)))))
}
4 changes: 4 additions & 0 deletions src/OsArchIndex.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
final case class OsArchIndex(map: Map[String, Map[String, String]]) {
def json: String =
Index.json2(map).render(indent = 2)
}

0 comments on commit e2e245e

Please sign in to comment.