From df89d5d66e60c06f291bc5287244cc15b30e73e9 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Wed, 16 Apr 2014 08:07:01 +0200 Subject: [PATCH 01/24] Prepare next version Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index c74d710aa..31520b7a3 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.0"; +version = "2.2.1-SNAPSHOT"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From 83370f81a395c1e257aa12c3a035d35b392e383a Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Wed, 16 Apr 2014 09:01:49 +0200 Subject: [PATCH 02/24] Main: default to loading schemas using the current directory as a URI Easily done since we already ensured schema existence by building a list of canonical files from the arguments. See issue #94. Signed-off-by: Francis Galiegue --- src/main/java/com/github/fge/jsonschema/main/cli/Main.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/fge/jsonschema/main/cli/Main.java b/src/main/java/com/github/fge/jsonschema/main/cli/Main.java index 24cee3992..4a9e2b37f 100644 --- a/src/main/java/com/github/fge/jsonschema/main/cli/Main.java +++ b/src/main/java/com/github/fge/jsonschema/main/cli/Main.java @@ -132,7 +132,8 @@ else if (optionSet.has("quiet")) { throws IOException { final URITranslatorConfigurationBuilder builder - = URITranslatorConfiguration.newBuilder(); + = URITranslatorConfiguration.newBuilder() + .setNamespace(getCwd()); if (fakeRoot != null) builder.addPathRedirect(fakeRoot, getCwd()); final LoadingConfiguration cfg = LoadingConfiguration.newBuilder() @@ -175,6 +176,7 @@ private RetCode doValidation(final Reporter reporter, throws IOException, ProcessingException { final File schemaFile = files.remove(0); + final String uri = schemaFile.toURI().normalize().toString(); JsonNode node; node = MAPPER.readTree(schemaFile); @@ -183,7 +185,7 @@ private RetCode doValidation(final Reporter reporter, return SCHEMA_SYNTAX_ERROR; } - final JsonSchema schema = factory.getJsonSchema(node); + final JsonSchema schema = factory.getJsonSchema(uri); RetCode ret = ALL_OK, retcode; From 07bb3162a821740da3f15261606fa9edd752d92d Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Wed, 16 Apr 2014 17:29:46 +0200 Subject: [PATCH 03/24] Main: improve help Signed-off-by: Francis Galiegue --- .../main/cli/CustomHelpFormatter.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java b/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java index e9577f33c..cbb441803 100644 --- a/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java +++ b/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java @@ -20,6 +20,7 @@ package com.github.fge.jsonschema.main.cli; import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import joptsimple.HelpFormatter; import joptsimple.OptionDescriptor; @@ -33,8 +34,24 @@ final class CustomHelpFormatter implements HelpFormatter { - private static final String HELP_PREAMBLE - = "Syntax: java -jar jsonschema.jar [options] file [file...]"; + private static final List HELP_PREAMBLE = ImmutableList.of( + "Syntax:", + " java -jar jsonschema.jar [options] schema file [file...]", + " java -jar jsonschema.jar --syntax [options] schema [schema...]", + "", + "Options: " + ); + + private static final List HELP_POST + = ImmutableList.builder() + .add("") + .add("Exit codes:") + .add(" 0: validation successful;") + .add(" 1: exception occurred (appears on stderr)") + .add(" 2: command line syntax error (missing argument, etc)") + .add(" 100: one or more file(s) failed validation") + .add(" 101: one or more schema(s) is/are invalid") + .build(); private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); @@ -50,9 +67,7 @@ public String format(final Map options) final Set opts = new LinkedHashSet( options.values()); - lines.add(HELP_PREAMBLE); - lines.add(""); - lines.add("Options: "); + lines.addAll(HELP_PREAMBLE); final int helpIndex = lines.size(); StringBuilder sb; @@ -72,13 +87,7 @@ public String format(final Map options) lines.add(sb.toString()); } - lines.add(""); - lines.add("Exit codes:"); - lines.add("\t0: validation successful;"); - lines.add("\t1: exception occurred (appears on stderr)"); - lines.add("\t2: command line syntax error (missing argument, etc)"); - lines.add("\t100: one or more file(s) failed validation"); - lines.add("\t101: one or more schema(s) is/are invalid"); + lines.addAll(HELP_POST); return JOINER.join(lines) + LINE_SEPARATOR; } From 6d8d5d1dc0e099836335f238daf88cfbb9cb9527 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Wed, 16 Apr 2014 18:08:09 +0200 Subject: [PATCH 04/24] Improve help for main Signed-off-by: Francis Galiegue --- .../fge/jsonschema/main/cli/CustomHelpFormatter.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java b/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java index cbb441803..95c6eaa4a 100644 --- a/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java +++ b/src/main/java/com/github/fge/jsonschema/main/cli/CustomHelpFormatter.java @@ -51,6 +51,12 @@ final class CustomHelpFormatter .add(" 2: command line syntax error (missing argument, etc)") .add(" 100: one or more file(s) failed validation") .add(" 101: one or more schema(s) is/are invalid") + .add("") + .add("Note: by default, the URI of schemas you use in validation mode") + .add("(that is, when you don't use --syntax) is considered to be the") + .add("current working directory plus the filename. If your schemas") + .add("all have a common URI prefix in a top level \"id\", you can fake") + .add("that the current directory is that prefix using --fakeroot.") .build(); private static final String LINE_SEPARATOR @@ -76,7 +82,7 @@ public String format(final Map options) if (descriptor.representsNonOptions()) continue; final Collection names = descriptor.options(); - sb = new StringBuilder().append('\t') + sb = new StringBuilder().append(" ") .append(optionsToString(names)); if (descriptor.requiresArgument()) sb.append(" uri"); From 168af10ea2fec9783d22ec18aac04fcae5dc27b7 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Wed, 16 Apr 2014 18:08:42 +0200 Subject: [PATCH 05/24] 2.2.1 Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index 31520b7a3..fa771d583 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.1-SNAPSHOT"; +version = "2.2.1"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From 4a77a17682d3f43a5dbc87260279caf26a806255 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Wed, 16 Apr 2014 18:25:48 +0200 Subject: [PATCH 06/24] Prepare for next version In 2.2.1: Francis Galiegue (5): Prepare next version Main: default to loading schemas using the current directory as a URI Main: improve help Improve help for main 2.2.1 Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index fa771d583..7d915a7a2 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.1"; +version = "2.2.2-SNAPSHOT"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From a0a037264a9acbe0342905c3dae0df2e0d095922 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Thu, 17 Apr 2014 18:26:37 +0200 Subject: [PATCH 07/24] Fill release notes Signed-off-by: Francis Galiegue --- RELEASE-NOTES.md | 75 +++--------------------------------------------- 1 file changed, 4 insertions(+), 71 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 58ffbf555..7adccf976 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,75 +1,8 @@ -### 2.1.10 +### 2.2.1 -* Plug in hyperschema syntax support... -* Gradle 1.11. -* Add a main method. -* -core 1.1.11. +* Main now uses current working directory as default URI namespace. -### 2.1.9 +### 2.2.0 -* Fix bug with string length calculations: it is the number of Unicode code - points which matters, not the number of `char`s (issue #92). -* Depend on -core 1.1.10: schema sources with trailing input are now considered - illegal. -* Make all tests run from the command line. -* Small javadoc fixes. - -### 2.1.8 - -* Add "deep validation": validate children even if container fails -* -core update to 1.1.9: package changes (BREAKS OLDER CODE) -* Change licensing to dual LGPLv3/ ASL 2.0 -* Dependencies updates (Joda Time 2.3, libphonenumber 5.9) - -### 2.1.7 - -* Import all format attributes from - [json-schema-formats](https://github.com/fge/json-schema-formats). -* Switch to gradle for build. -* Major dependencies updates; drop ServiceLoader for message bundles. -* Fix javadoc generation. - -### 2.1.6 - -* Update json-schema-core dependency to 1.1.7. -* Fix a bug in pom.xml which would cause the service file to not be generated. -* Fix two places where core messages would not be fetched properly. - -### 2.1.5 - -* Update json-schema-core dependency to 1.1.6. -* Use [msg-simple](https://github.com/fge/msg-simple) for message bundles. -* Remove all unchecked exceptions, now unneeded. -* Improve, test all error messages. -* pom.xml improvements. -* Remove obsolete code. - -### 2.1.4 - -* Update -core dependency. -* Use resource bundles for all configuration/validation messages (issue #55). -* Modify pom.xml to allow OSGi-capable deployments (courtesy of Matt Bishop). - -### 2.1.3 - -* Modify date/time format checkings to accurately check for the required number - of digits - -### 2.1.2 - -* Update -core dependency to 1.1.3 -* Update libphonenumber dependency - -### 2.1.1 - -* Update -core dependency (including Guava), adapt code. -* Some error message rework. - -### 2.1.0 - -* Depend on -core 1.1.1. Change relevant code accordingly. -* Simplify failure code on syntax validation failure. -* Fix `date-time` format checking: up to three millisecond digits are allowed by -* ISO 8601. -* Joda Time dependency updated to 2.2. +* New major release. From 5e9242f688450d90eaa9bfaf896b6d178d88ed12 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Thu, 17 Apr 2014 18:27:05 +0200 Subject: [PATCH 08/24] Depend on -core 1.2.1 to fix Rhino bug Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index 7d915a7a2..acc16b334 100644 --- a/project.gradle +++ b/project.gradle @@ -34,7 +34,7 @@ project.ext { */ dependencies { compile(group: "com.github.fge", name: "json-schema-core", - version: "1.2.0"); + version: "1.2.1"); compile(group: "javax.mail", name: "mailapi", version: "1.4.3"); compile(group: "joda-time", name: "joda-time", version: "2.3"); compile(group: "com.googlecode.libphonenumber", name: "libphonenumber", From 828f1d6c1d7020599bb722f4c5447c5536f038a4 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Thu, 17 Apr 2014 18:27:31 +0200 Subject: [PATCH 09/24] 2.2.2 Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index acc16b334..d3e8b409d 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.2-SNAPSHOT"; +version = "2.2.2"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From ab3e324d34ec61d73810a8b5004bbaf554920a82 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Thu, 17 Apr 2014 18:36:06 +0200 Subject: [PATCH 10/24] Release notes completion Signed-off-by: Francis Galiegue --- RELEASE-NOTES.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 7adccf976..fbe0d9a5b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,12 @@ +### 2.2.3 + +* Re-release... 2.2.2 was compiled with JDK 8 :/ + +### 2.2.2 + +* Depend on -core 1.2.1 to work around Rhino bug with other packages sealing the + context. + ### 2.2.1 * Main now uses current working directory as default URI namespace. From e6a343100aede7c34f0b84b70ffac56bf63a11f3 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Thu, 17 Apr 2014 18:34:11 +0200 Subject: [PATCH 11/24] 2.2.3 Argh. Compiled 2.2.2 with Java 8. Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index d3e8b409d..ee3e9c3db 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.2"; +version = "2.2.3"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From dc9bf4b4d64655987cc72e32670480d5891a75a8 Mon Sep 17 00:00:00 2001 From: Pablo Pinheiro Date: Tue, 29 Apr 2014 09:23:41 -0300 Subject: [PATCH 12/24] Added a lib jar to the build --- build.gradle | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/build.gradle b/build.gradle index cc23d4051..90ab40c6d 100644 --- a/build.gradle +++ b/build.gradle @@ -128,11 +128,22 @@ task fullJar(type: OneJar) { archiveName = "jsonschema.jar"; } +/* + * Creates a jar that can be used as a library on java projects. + * This jar already includes all the dependencies. + */ +task libJar(type: Jar, dependsOn: jar) { + appendix = "lib" + from {configurations.compile.collect {zipTree(it)}} + with jar +} + artifacts { archives jar; archives sourcesJar; archives javadocJar; archives fullJar; + archives libJar; } task wrapper(type: Wrapper) { From 555c5874b7fabe5bfb8b8a2e22abb9df917cca68 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Fri, 23 May 2014 10:38:21 +0200 Subject: [PATCH 13/24] Fill in RELEASE-NOTES and CONTRIBUTORS Signed-off-by: Francis Galiegue --- CONTRIBUTORS.md | 4 ++++ RELEASE-NOTES.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c4a831b4a..be0f72403 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,3 +1,7 @@ +### Pablo Pinhero + +* Add a "lib" target to the build: jar with all dependencies builtin. + ### Corey Sciuto * Tests for date-time format attribute; date-time-millis format attribute (now diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index fbe0d9a5b..48a147e2b 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,7 @@ +### 2.2.4 (not released yet) + +* Add a "lib" target to the build + ### 2.2.3 * Re-release... 2.2.2 was compiled with JDK 8 :/ From 41066f2ae2dd4dc62409dcddb5c26cd428757a5a Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Fri, 23 May 2014 10:41:34 +0200 Subject: [PATCH 14/24] Bump version Signed-off-by: Francis Galiegue --- build.gradle | 4 +++- project.gradle | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 90ab40c6d..8d322f38e 100644 --- a/build.gradle +++ b/build.gradle @@ -134,7 +134,9 @@ task fullJar(type: OneJar) { */ task libJar(type: Jar, dependsOn: jar) { appendix = "lib" - from {configurations.compile.collect {zipTree(it)}} + from { + configurations.compile.collect { zipTree(it) } + } with jar } diff --git a/project.gradle b/project.gradle index ee3e9c3db..5f946dcb7 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.3"; +version = "2.2.4-SNAPSHOT"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From 44374baa9bd73bf723cc42ee7481c6412b380bcf Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Fri, 23 May 2014 11:48:05 +0200 Subject: [PATCH 15/24] Output syntax errors when throwing an InvalidSchemaException For this, depend on -core 1.2.3 (which fixes a missing key) and walk the previous report to search for syntax errors; append these to the ProcessingMessage we use to initialize the exception. Fixes issue #99. Signed-off-by: Francis Galiegue --- project.gradle | 2 +- .../validation/ValidationProcessor.java | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/project.gradle b/project.gradle index 5f946dcb7..93fba1b2d 100644 --- a/project.gradle +++ b/project.gradle @@ -34,7 +34,7 @@ project.ext { */ dependencies { compile(group: "com.github.fge", name: "json-schema-core", - version: "1.2.1"); + version: "1.2.3"); compile(group: "javax.mail", name: "mailapi", version: "1.4.3"); compile(group: "joda-time", name: "joda-time", version: "2.3"); compile(group: "com.googlecode.libphonenumber", name: "libphonenumber", diff --git a/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationProcessor.java b/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationProcessor.java index 2e6dde82f..c824c14e8 100644 --- a/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationProcessor.java +++ b/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationProcessor.java @@ -20,6 +20,8 @@ package com.github.fge.jsonschema.processors.validation; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.github.fge.jackson.JacksonUtils; import com.github.fge.jackson.jsonpointer.JsonPointer; import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.core.exceptions.InvalidSchemaException; @@ -83,9 +85,27 @@ public FullData process(final ProcessingReport report, */ final ValidatorList fullContext = processor.process(report, context); - if (fullContext == null) - throw new InvalidSchemaException(new ProcessingMessage() - .setMessage(syntaxMessages.getMessage("core.invalidSchema"))); + if (fullContext == null) { + /* + * OK, that's for issue #99 but that's ugly nevertheless. + * + * We want syntax error messages to appear in the exception text. + */ + final String msg = syntaxMessages.getMessage("core.invalidSchema"); + final ArrayNode arrayNode = JacksonUtils.nodeFactory().arrayNode(); + JsonNode node; + for (final ProcessingMessage message: report) { + node = message.asJson(); + if ("syntax".equals(node.path("domain").asText())) + arrayNode.add(node); + } + final StringBuilder sb = new StringBuilder(msg); + sb.append("\nSyntax errors:\n"); + sb.append(JacksonUtils.prettyPrint(arrayNode)); + final ProcessingMessage message = new ProcessingMessage() + .setMessage(sb.toString()); + throw new InvalidSchemaException(message); + } /* * Get the calculated context. Build the data. From 4440eb1d83f970174f4ef365cd89e75af65cd780 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Fri, 23 May 2014 11:54:48 +0200 Subject: [PATCH 16/24] Fill release notes Signed-off-by: Francis Galiegue --- RELEASE-NOTES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 48a147e2b..65ae2fe46 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,6 +1,9 @@ ### 2.2.4 (not released yet) -* Add a "lib" target to the build +* Add a "lib" target to the build. +* Issue #99: append syntax errors when throwing an InvalidSchemaException. +* Issue #100: attempt to load resources from the context classloader if loading + from JsonLoader.class fails. ### 2.2.3 From 438e5169cf9964c73fb2413432173486da06996c Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Fri, 23 May 2014 12:00:09 +0200 Subject: [PATCH 17/24] Fix libJar task: add different classifier "appendix" is not enough. --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 8d322f38e..5f9fbc12c 100644 --- a/build.gradle +++ b/build.gradle @@ -133,11 +133,11 @@ task fullJar(type: OneJar) { * This jar already includes all the dependencies. */ task libJar(type: Jar, dependsOn: jar) { - appendix = "lib" + classifier = "lib"; from { configurations.compile.collect { zipTree(it) } - } - with jar + }; + with jar; } artifacts { From 71db68228b77f05b7f11849328006e2dcf080d47 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Fri, 23 May 2014 11:56:52 +0200 Subject: [PATCH 18/24] 2.2.4 Signed-off-by: Francis Galiegue --- RELEASE-NOTES.md | 2 +- project.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 65ae2fe46..a59a0c25d 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,4 +1,4 @@ -### 2.2.4 (not released yet) +### 2.2.4 * Add a "lib" target to the build. * Issue #99: append syntax errors when throwing an InvalidSchemaException. diff --git a/project.gradle b/project.gradle index 93fba1b2d..af77839dc 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.4-SNAPSHOT"; +version = "2.2.4"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From 4834e5b304029746feb74c79ccf8c7a8c54a3e78 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 10:34:16 +0200 Subject: [PATCH 19/24] Bump version number Signed-off-by: Francis Galiegue --- project.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.gradle b/project.gradle index af77839dc..7f9ac59b6 100644 --- a/project.gradle +++ b/project.gradle @@ -21,7 +21,7 @@ * Project-specific settings. Unfortunately we cannot put the name in there! */ group = "com.github.fge"; -version = "2.2.4"; +version = "2.2.5-SNAPSHOT"; sourceCompatibility = "1.6"; targetCompatibility = "1.6"; // defaults to sourceCompatibility From de1987804d837f4ce40bc4f95321aa27d3305567 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 13:05:57 +0200 Subject: [PATCH 20/24] Depend on local -SNAPSHOT Signed-off-by: Francis Galiegue --- build.gradle | 1 + project.gradle | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5f9fbc12c..5d67bc776 100644 --- a/build.gradle +++ b/build.gradle @@ -72,6 +72,7 @@ apply(from: "project.gradle"); */ repositories { mavenCentral(); + mavenLocal(); } /* diff --git a/project.gradle b/project.gradle index 7f9ac59b6..180ed8352 100644 --- a/project.gradle +++ b/project.gradle @@ -34,7 +34,7 @@ project.ext { */ dependencies { compile(group: "com.github.fge", name: "json-schema-core", - version: "1.2.3"); + version: "1.2.4-SNAPSHOT"); compile(group: "javax.mail", name: "mailapi", version: "1.4.3"); compile(group: "joda-time", name: "joda-time", version: "2.3"); compile(group: "com.googlecode.libphonenumber", name: "libphonenumber", From 2f5d63ab89cc3efaa102af6c614991f65296563f Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 10:06:35 +0200 Subject: [PATCH 21/24] Make test to reproduce issue #102 Signed-off-by: Francis Galiegue --- .../validation/ValidationProcessorTest.java | 21 +++++++++++-- src/test/resources/other/issue102.json | 30 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/other/issue102.json diff --git a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java index 65af8a23c..f51123c01 100644 --- a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java +++ b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import com.github.fge.jackson.JacksonUtils; +import com.github.fge.jackson.JsonLoader; import com.github.fge.jackson.NodeType; import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.core.exceptions.ProcessingException; @@ -39,15 +40,18 @@ import com.github.fge.jsonschema.library.Keyword; import com.github.fge.jsonschema.library.Library; import com.github.fge.jsonschema.main.JsonSchemaFactory; +import com.github.fge.jsonschema.main.JsonValidator; import com.github.fge.jsonschema.processors.data.FullData; import com.github.fge.msgsimple.bundle.MessageBundle; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import static org.mockito.Mockito.*; -import static org.testng.Assert.*; +import static org.mockito.Mockito.mock; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; public final class ValidationProcessorTest { @@ -111,6 +115,19 @@ public void childrenAreExploredOnDemandEvenIfContainerFails() assertEquals(COUNT.get(), 1); } + @Test(timeOut = 1000) + public void circularReferencingDuringValidationIsDetected() + throws IOException, ProcessingException + { + final JsonNode schemaNode + = JsonLoader.fromResource("/other/issue102.json"); + final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); + final JsonValidator validator = factory.getValidator(); + + validator.validate(schemaNode, JacksonUtils.nodeFactory().nullNode()); + assertTrue(true); + } + public static final class K1Validator extends AbstractKeywordValidator { diff --git a/src/test/resources/other/issue102.json b/src/test/resources/other/issue102.json new file mode 100644 index 000000000..1af9832c3 --- /dev/null +++ b/src/test/resources/other/issue102.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "definitions": { + "S": { + "allOf": [ + { + "type": "string", + "enum": ["a"] + }, + { + "oneOf": [ + { + "$ref": "#/definitions/S" + }, + { + "type": "string", + "enum": [""] + } + ] + }, + { + "type": "string", + "enum": ["b"] + } + ], + "additionalItems": false + } + }, + "$ref": "#/definitions/S" +} \ No newline at end of file From 0fafd3ea061c8f0fac7620ef662871cda6366918 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 13:15:19 +0200 Subject: [PATCH 22/24] SchemaContextEquivalence: remove reference to SchemaTreeEquivalence Use SchemaTree's equals()/hashCode() instead Signed-off-by: Francis Galiegue --- .../validation/SchemaContextEquivalence.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/fge/jsonschema/processors/validation/SchemaContextEquivalence.java b/src/main/java/com/github/fge/jsonschema/processors/validation/SchemaContextEquivalence.java index c978d41a6..8f07d7a68 100644 --- a/src/main/java/com/github/fge/jsonschema/processors/validation/SchemaContextEquivalence.java +++ b/src/main/java/com/github/fge/jsonschema/processors/validation/SchemaContextEquivalence.java @@ -19,8 +19,6 @@ package com.github.fge.jsonschema.processors.validation; -import com.github.fge.jsonschema.core.tree.SchemaTree; -import com.github.fge.jsonschema.core.util.equivalence.SchemaTreeEquivalence; import com.github.fge.jsonschema.processors.data.SchemaContext; import com.google.common.base.Equivalence; @@ -36,7 +34,6 @@ *
  • and the type of the instance is the same.
  • * * - * @see SchemaTreeEquivalence */ public final class SchemaContextEquivalence extends Equivalence @@ -44,9 +41,6 @@ public final class SchemaContextEquivalence private static final Equivalence INSTANCE = new SchemaContextEquivalence(); - private static final Equivalence TREE_EQUIVALENCE - = SchemaTreeEquivalence.getInstance(); - public static Equivalence getInstance() { return INSTANCE; @@ -55,14 +49,13 @@ public static Equivalence getInstance() @Override protected boolean doEquivalent(final SchemaContext a, final SchemaContext b) { - return TREE_EQUIVALENCE.equivalent(a.getSchema(), b.getSchema()) + return a.getSchema().equals(b.getSchema()) && a.getInstanceType() == b.getInstanceType(); } @Override protected int doHash(final SchemaContext t) { - return 31 * TREE_EQUIVALENCE.hash(t.getSchema()) - + t.getInstanceType().hashCode(); + return t.getSchema().hashCode() ^ t.getInstanceType().hashCode(); } } From afcbb4ea01a746eb74e4f919d7833ba5a45ecb92 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 13:29:08 +0200 Subject: [PATCH 23/24] ValidationChain: drop use of SchemaTreeEquivalence Signed-off-by: Francis Galiegue --- .../processors/validation/ValidationChain.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationChain.java b/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationChain.java index 65062b4a7..bc4e4ad9e 100644 --- a/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationChain.java +++ b/src/main/java/com/github/fge/jsonschema/processors/validation/ValidationChain.java @@ -30,7 +30,6 @@ import com.github.fge.jsonschema.core.report.ProcessingReport; import com.github.fge.jsonschema.core.tree.SchemaTree; import com.github.fge.jsonschema.core.util.ValueHolder; -import com.github.fge.jsonschema.core.util.equivalence.SchemaTreeEquivalence; import com.github.fge.jsonschema.library.Library; import com.github.fge.jsonschema.processors.build.ValidatorBuilder; import com.github.fge.jsonschema.processors.data.SchemaContext; @@ -39,6 +38,8 @@ import com.github.fge.jsonschema.processors.format.FormatProcessor; import com.google.common.base.Equivalence; +import javax.annotation.ParametersAreNonnullByDefault; + /** * A validation chain * @@ -80,8 +81,7 @@ public ValidationChain(final RefResolver refResolver, = ProcessorChain.startWith(digester).chainWith(keywordBuilder); if (cfg.getUseFormat()) { - final FormatProcessor format - = new FormatProcessor(library, cfg); + final FormatProcessor format = new FormatProcessor(library, cfg); chain2 = chain2.chainWith(format); } @@ -120,26 +120,24 @@ public String toString() return resolver + " -> " + builder; } + @ParametersAreNonnullByDefault private static final class SchemaHolderEquivalence extends Equivalence> { private static final Equivalence> INSTANCE = new SchemaHolderEquivalence(); - private static final Equivalence EQUIVALENCE - = SchemaTreeEquivalence.getInstance(); - @Override protected boolean doEquivalent(final ValueHolder a, final ValueHolder b) { - return EQUIVALENCE.equivalent(a.getValue(), b.getValue()); + return a.getValue().equals(b.getValue()); } @Override protected int doHash(final ValueHolder t) { - return EQUIVALENCE.hash(t.getValue()); + return t.getValue().hashCode(); } } } From 8ad8249fed98e8eb66d67e77f918d470e7f4edb6 Mon Sep 17 00:00:00 2001 From: Francis Galiegue Date: Sat, 24 May 2014 14:02:50 +0200 Subject: [PATCH 24/24] Modify tests; add a message for validation loops Signed-off-by: Francis Galiegue --- .../jsonschema/validator/validation.properties | 5 +++++ .../validation/ValidationProcessorTest.java | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/resources/com/github/fge/jsonschema/validator/validation.properties b/src/main/resources/com/github/fge/jsonschema/validator/validation.properties index 99ac7b4a7..380eb5c22 100644 --- a/src/main/resources/com/github/fge/jsonschema/validator/validation.properties +++ b/src/main/resources/com/github/fge/jsonschema/validator/validation.properties @@ -74,3 +74,8 @@ err.format.jsonpointer.invalid = input string "%s" is not a valid JSON Pointer err.format.macAddr.invalid = input string "%s" is not a valid MAC address err.format.uriTemplate.invalid = input string "%s" is not a valid URI template err.format.UUID.invalid = input string "%s" is not a valid UUID + +# +# Other messages +# +err.common.validationLoop = validation loop detected diff --git a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java index f51123c01..5fa85df26 100644 --- a/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java +++ b/src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java @@ -41,8 +41,10 @@ import com.github.fge.jsonschema.library.Library; import com.github.fge.jsonschema.main.JsonSchemaFactory; import com.github.fge.jsonschema.main.JsonValidator; +import com.github.fge.jsonschema.messages.JsonSchemaValidationBundle; import com.github.fge.jsonschema.processors.data.FullData; import com.github.fge.msgsimple.bundle.MessageBundle; +import com.github.fge.msgsimple.load.MessageBundles; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -52,6 +54,7 @@ import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; public final class ValidationProcessorTest { @@ -123,8 +126,18 @@ public void circularReferencingDuringValidationIsDetected() = JsonLoader.fromResource("/other/issue102.json"); final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); final JsonValidator validator = factory.getValidator(); - - validator.validate(schemaNode, JacksonUtils.nodeFactory().nullNode()); + final MessageBundle bundle + = MessageBundles.getBundle(JsonSchemaValidationBundle.class); + final String expectedMsg + = bundle.getMessage("err.common.validationLoop"); + + try { + validator.validate(schemaNode, + JacksonUtils.nodeFactory().nullNode()); + fail("No exception thrown!"); + } catch (ProcessingException e) { + assertEquals(e.getMessage(), expectedMsg); + } assertTrue(true); }