diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 840e80e..f1de8da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,9 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.12.5' + - uses: oven-sh/setup-bun@v2 + with: + bun-version: latest - name: Install uv run: pipx install uv diff --git a/Makefile b/Makefile index ed8ceaa..bcf0c53 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,10 @@ define docker_run @sed -i 's/$$/,$(.SHELLSTATUS)/' $@ endef +schemas/%/schema-2020-12.json: \ + schemas/%/schema.json + bunx alterschema --from draft4 --to 2020-12 $< > $@ + # JSON Toolkit implementations/jsontoolkit/.dockertimestamp: \ @@ -134,3 +138,22 @@ dist/results/go-jsonschema/%: \ schemas/%/instances.jsonl \ | dist/results/go-jsonschema @$(call docker_run,go-jsonschema,/workspace/$(dir $(word 2,$^))) + +# MJS + +implementations/mjs/.dockertimestamp: \ + implementations/mjs/build.sbt \ + implementations/mjs/Benchmark.scala \ + implementations/mjs/project/build.properties \ + implementations/mjs/project/plugins.sbt \ + implementations/mjs/Dockerfile + docker build -t jsonschema-benchmark/mjs implementations/mjs + touch $@ + +dist/results/mjs/%: \ + implementations/mjs/.dockertimestamp \ + schemas/%/schema-2020-12.json \ + schemas/%/instances.jsonl \ + | dist/results/mjs + @$(call docker_run,mjs,/workspace/$(word 2,$^) /workspace/$(word 3,$^)) + diff --git a/implementations/mjs/Benchmark.scala b/implementations/mjs/Benchmark.scala new file mode 100644 index 0000000..12bf025 --- /dev/null +++ b/implementations/mjs/Benchmark.scala @@ -0,0 +1,28 @@ +import main.MainClass + +import scala.io.Source + +object Benchmark { + def main(args: Array[String]): Unit = { + if (args.length != 2) { + System.exit(1) + } + val schemaPath = args(0) + val instancePath = args(1) + + val schema = Source.fromFile(schemaPath).mkString + val registryMap = Map.empty[String, String] + + val start = System.nanoTime() + for (instance <- Source.fromFile(instancePath).getLines()) { + val result = MainClass.validateInstance(schema, instance, registryMap) + if (!result) { + System.err.println("Invalid instance") + System.exit(1) + } + } + val finish = System.nanoTime() + + println((finish - start).toString) + } +} diff --git a/implementations/mjs/Dockerfile b/implementations/mjs/Dockerfile new file mode 100644 index 0000000..29555d0 --- /dev/null +++ b/implementations/mjs/Dockerfile @@ -0,0 +1,9 @@ +FROM sbtscala/scala-sbt:eclipse-temurin-17.0.4_1.7.2_2.13.10 AS builder + +WORKDIR /app +COPY Benchmark.scala /app +COPY build.sbt /app +COPY project /app/project +RUN sbt assembly +ENTRYPOINT ["java", "-jar", "/app/target/scala-2.13/benchmarkMjs.jar"] +CMD [] diff --git a/implementations/mjs/build.sbt b/implementations/mjs/build.sbt new file mode 100644 index 0000000..c5c4d12 --- /dev/null +++ b/implementations/mjs/build.sbt @@ -0,0 +1,29 @@ +name := "mjs-validator" + +ThisBuild / version := "1.0" +ThisBuild / scalaVersion := "2.13.10" + +javacOptions ++= Seq("-source", "17", "-target", "17") + +resolvers += Resolver.mavenCentral + +libraryDependencies ++= Seq( + "org.scala-lang" % "scala-library" % "2.13.10" +) + +val mjsVersion = "v0.1.0" +lazy val mjs = RootProject( + uri(s"https://gitlab.lip6.fr/jsonschema/modernjsonschemavalidator.git#$mjsVersion") +) +lazy val benchmarkMjs = (project in file(".")).dependsOn(mjs) +assembly / assemblyJarName := "benchmarkMjs.jar" +assembly / packageOptions := Seq( + Package.ManifestAttributes( + "Main-Class" -> "Benchmark", + "Implementation-Group" -> "org.up.mjs", + "Implementation-Name" -> "mjs", + "Implementation-Version" -> mjsVersion + ) +) + +scalacOptions += "-Ymacro-annotations" diff --git a/implementations/mjs/project/build.properties b/implementations/mjs/project/build.properties new file mode 100644 index 0000000..2743082 --- /dev/null +++ b/implementations/mjs/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.9.6 diff --git a/implementations/mjs/project/plugins.sbt b/implementations/mjs/project/plugins.sbt new file mode 100644 index 0000000..d83c883 --- /dev/null +++ b/implementations/mjs/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.5") diff --git a/implementations/mjs/version.sh b/implementations/mjs/version.sh new file mode 100755 index 0000000..6b40408 --- /dev/null +++ b/implementations/mjs/version.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +grep '^val mjsVersion =' implementations/mjs/build.sbt | cut -d= -f2 | tr -d '" '