From 2bc4ff3b0c85d44b5b89487df70665f0939df782 Mon Sep 17 00:00:00 2001 From: simonpoole Date: Tue, 3 Dec 2024 17:45:30 +0100 Subject: [PATCH] Fix validation (plugin no longer words) and add publishing --- .project | 11 ----- .settings/org.eclipse.buildship.core.prefs | 2 - build.gradle | 54 ++++++++++++++++++---- 3 files changed, 44 insertions(+), 23 deletions(-) delete mode 100644 .project delete mode 100644 .settings/org.eclipse.buildship.core.prefs diff --git a/.project b/.project deleted file mode 100644 index d393250..0000000 --- a/.project +++ /dev/null @@ -1,11 +0,0 @@ - - - geocontext - - - - - - - - diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs deleted file mode 100644 index 408b507..0000000 --- a/.settings/org.eclipse.buildship.core.prefs +++ /dev/null @@ -1,2 +0,0 @@ -connection.project.dir= -eclipse.preferences.version=1 diff --git a/build.gradle b/build.gradle index 96dd8c9..c92a92d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,25 +1,59 @@ buildscript { repositories { - jcenter() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath 'cz.alenkacz.gradle:json-validator:1.3.0' - } + classpath "com.github.breadmoirai:github-release:2.5.2" + classpath(group: "com.github.java-json-tools", name: "json-schema-validator", version: "2.2.14"); + } } -apply plugin: 'json-validator' +apply plugin: "com.github.breadmoirai.github-release" + +import com.fasterxml.jackson.databind.JsonNode; +import com.github.fge.jackson.JsonLoader; +import com.github.fge.jsonschema.core.report.ProcessingReport; +import com.github.fge.jsonschema.main.JsonSchema; +import com.github.fge.jsonschema.main.JsonSchemaFactory; + +ext { + version = '0.1.0' + schema_file = projectDir.getPath() + "/schema.json" + data_file = projectDir.getPath() + "/geocontext.json" + githubToken = System.getenv('GITHUB_TOKEN') +} -import cz.alenkacz.gradle.jsonvalidator.ValidateJsonTask +task validate() { + inputs.file(schema_file); + inputs.file(data_file); + doLast { + final JsonNode schemaFile = JsonLoader.fromPath(schema_file); + final JsonNode toValidate = JsonLoader.fromPath(data_file); + + final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); + final JsonSchema schema = factory.getJsonSchema(schemaFile); -task validate(type: ValidateJsonTask) { - targetJsonFile = file("geocontext.json") // only one of targetJsonFile or targetJsonDirectory can be specified - jsonSchema = file("schema.json") - onlyWithJsonExtension = true + ProcessingReport report = schema.validate(toValidate); + if (!report.isSuccess()) { + throw new GradleException(report.toString()); + } + } } validate.group = 'validation' -validate.description = 'Vaidate geocontext.json' \ No newline at end of file +validate.description = 'Vaidate the json data' + +githubRelease { + token project.ext.githubToken == null ? "" : project.ext.githubToken + owner = "simonpoole" + tagName = project.ext.version + releaseName = project.ext.version + targetCommitish = "main" + generateReleaseNotes = true + + releaseAssets data_file, schema_file + overwrite = true +} \ No newline at end of file