Skip to content

Commit 62367a9

Browse files
committed
Add harrel-json-schema implementation
1 parent 70922d9 commit 62367a9

File tree

15 files changed

+522
-0
lines changed

15 files changed

+522
-0
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
report-boon: ${{ steps.save-output.outputs.report-boon }}
5656
report-corvus: ${{ steps.save-output.outputs.report-corvus }}
5757
report-go-jsonschema: ${{ steps.save-output.outputs.report-go-jsonschema }}
58+
report-harrel-json-schema: ${{ steps.save-output.outputs.report-harrel-json-schema }}
5859
report-hyperjump: ${{ steps.save-output.outputs.report-hyperjump }}
5960
report-json_schemer: ${{ steps.save-output.outputs.report-json_schemer }}
6061
report-jsoncons: ${{ steps.save-output.outputs.report-jsoncons }}

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,22 @@ dist/results/kmp-json-schema-validator/%: \
257257
schemas/%/instances.jsonl \
258258
| dist/results/kmp-json-schema-validator
259259
@$(call docker_run,kmp-json-schema-validator,/workspace/$(word 2,$^) /workspace/$(word 3,$^))
260+
261+
# harrel-json-schema
262+
263+
implementations/harrel-json-schema/.dockertimestamp: \
264+
implementations/harrel-json-schema/app/src/main/java/io/github/sourcemeta/App.java \
265+
implementations/harrel-json-schema/app/build.gradle.kts \
266+
implementations/harrel-json-schema/gradle/libs.versions.toml \
267+
implementations/harrel-json-schema/gradle/wrapper/gradle-wrapper.properties \
268+
implementations/harrel-json-schema/run.sh \
269+
implementations/harrel-json-schema/Dockerfile
270+
docker build -t jsonschema-benchmark/harrel-json-schema implementations/harrel-json-schema
271+
touch $@
272+
273+
dist/results/harrel-json-schema/%: \
274+
implementations/harrel-json-schema/.dockertimestamp \
275+
schemas/%/schema.json \
276+
schemas/%/instances.jsonl \
277+
| dist/results/harrel-json-schema
278+
@$(call docker_run,harrel-json-schema,/workspace/$(word 2,$^) /workspace/$(word 3,$^))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# syntax=docker.io/docker/dockerfile:1.7-labs
2+
FROM gradle:8.11.1-jdk21
3+
4+
COPY --exclude=./app/src . /app
5+
6+
WORKDIR /app
7+
8+
# Just download dependencies first
9+
RUN gradle downloadDependencies
10+
11+
# Now copy in the source and compile
12+
COPY ./app/src /app/app/src
13+
RUN gradle compileJava
14+
15+
ENTRYPOINT ["/app/run.sh"]
16+
CMD []
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
// Apply the application plugin to add support for building a CLI application in Java.
3+
application
4+
}
5+
6+
repositories {
7+
// Use Maven Central for resolving dependencies.
8+
mavenCentral()
9+
}
10+
11+
dependencies {
12+
// This dependency is used by the application.
13+
implementation(libs.jacksonDatabind)
14+
implementation(libs.jsonSchema)
15+
}
16+
17+
// Apply a specific Java toolchain to ease working on different environments.
18+
java {
19+
toolchain {
20+
languageVersion = JavaLanguageVersion.of(21)
21+
}
22+
}
23+
24+
application {
25+
// Define the main class for the application.
26+
mainClass = "io.github.sourcemeta.App"
27+
}
28+
//
29+
// See https://stackoverflow.com/a/38528497/123695
30+
fun ConfigurationContainer.resolveAll() = this
31+
.filter { it.isCanBeResolved }
32+
.forEach { it.resolve() }
33+
34+
tasks.register("downloadDependencies") {
35+
doLast {
36+
configurations.resolveAll()
37+
buildscript.configurations.resolveAll()
38+
}
39+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package io.github.sourcemeta;
2+
3+
import dev.harrel.jsonschema.Validator;
4+
import dev.harrel.jsonschema.ValidatorFactory;
5+
import java.io.IOException;
6+
import java.lang.Math;
7+
import java.net.URI;
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
10+
import java.util.List;
11+
12+
public class App {
13+
static int WARMUP_ITERATIONS = 1000;
14+
static long MAX_WARMUP_TIME = (long) 1e9 * 10;
15+
16+
public static boolean validateAll(Validator validator, URI schemaUri, List<String> docs) {
17+
boolean valid = true;
18+
for (String doc : docs) {
19+
Validator.Result result = validator.validate(schemaUri, doc);
20+
if (!result.isValid()) {
21+
valid = false;
22+
}
23+
}
24+
return valid;
25+
}
26+
27+
public static void main(String[] args) throws IOException {
28+
Validator validator = new ValidatorFactory().createValidator();
29+
String schema = new String(Files.readAllBytes(Paths.get(args[0])));
30+
31+
// Register the schema
32+
Long compileStart = System.nanoTime();
33+
URI schemaUri = validator.registerSchema(schema);
34+
Long compileEnd = System.nanoTime();
35+
36+
List<String> docs = Files.readAllLines(Paths.get(args[1]));
37+
38+
Long coldStart = System.nanoTime();
39+
boolean valid = validateAll(validator, schemaUri, docs);
40+
Long coldEnd = System.nanoTime();
41+
42+
if (!valid) {
43+
System.exit(1);
44+
}
45+
46+
// Warmup
47+
long iterations = (long) Math.ceil(((double) MAX_WARMUP_TIME) / (coldEnd - coldStart));
48+
for (int i = 0; i < WARMUP_ITERATIONS; i++) {
49+
validateAll(validator, schemaUri, docs);
50+
}
51+
52+
Long warmStart = System.nanoTime();
53+
validateAll(validator, schemaUri, docs);
54+
Long warmEnd = System.nanoTime();
55+
56+
System.out.println((coldEnd - coldStart) + "," + (warmEnd - warmStart) + "," + (compileEnd - compileStart));
57+
}
58+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[versions]
2+
jackson = "2.18.1"
3+
jsonSchema = "1.7.1"
4+
5+
[libraries]
6+
jacksonDatabind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
7+
jsonSchema = { module = "dev.harrel:json-schema", version.ref = "jsonSchema" }
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)