From 0805ae98fa690d89b4ce5525437dd7bcfd9c876d Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sat, 24 Oct 2020 20:41:45 +0000 Subject: [PATCH 01/12] Begin next development iteration --- com.io7m.blackthorne.api/pom.xml | 2 +- com.io7m.blackthorne.jxe/pom.xml | 2 +- com.io7m.blackthorne.tests/pom.xml | 2 +- pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/com.io7m.blackthorne.api/pom.xml b/com.io7m.blackthorne.api/pom.xml index 87a87c0..5347e8c 100644 --- a/com.io7m.blackthorne.api/pom.xml +++ b/com.io7m.blackthorne.api/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.0 + 1.1.1-SNAPSHOT com.io7m.blackthorne.api diff --git a/com.io7m.blackthorne.jxe/pom.xml b/com.io7m.blackthorne.jxe/pom.xml index 8de1de3..6b069a2 100644 --- a/com.io7m.blackthorne.jxe/pom.xml +++ b/com.io7m.blackthorne.jxe/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.0 + 1.1.1-SNAPSHOT com.io7m.blackthorne.jxe diff --git a/com.io7m.blackthorne.tests/pom.xml b/com.io7m.blackthorne.tests/pom.xml index fb694a6..9baf51e 100644 --- a/com.io7m.blackthorne.tests/pom.xml +++ b/com.io7m.blackthorne.tests/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.0 + 1.1.1-SNAPSHOT com.io7m.blackthorne.tests diff --git a/pom.xml b/pom.xml index 8162b27..30a651a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.0 + 1.1.1-SNAPSHOT pom com.io7m.blackthorne From 216a1bc627fb2c6a4257718f8956158adcdb0937 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Fri, 11 Dec 2020 14:41:07 +0000 Subject: [PATCH 02/12] Use primogenitor 6.1.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30a651a..84590c8 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.io7m.primogenitor com.io7m.primogenitor.full - 6.0.0 + 6.1.0 com.io7m.blackthorne From ecaf8f1a48139cf7f7b3e389155e5e867beabfc3 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Fri, 11 Dec 2020 15:13:06 +0000 Subject: [PATCH 03/12] Empty commit to trigger CI build From 796d5ad9df7846f2d51ba00a2919ef8f9da15cb1 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Mon, 28 Dec 2020 13:12:28 +0000 Subject: [PATCH 04/12] Update primogenitor --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 84590c8..9a916ed 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.io7m.primogenitor com.io7m.primogenitor.full - 6.1.0 + 6.2.0 com.io7m.blackthorne From 2a53626f9674d760f6526bc0d11ad194a7801bd2 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sat, 2 Jan 2021 16:29:15 +0000 Subject: [PATCH 05/12] Update jenkins files --- .jenkins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins b/.jenkins index 525f013..4b5bbb1 160000 --- a/.jenkins +++ b/.jenkins @@ -1 +1 @@ -Subproject commit 525f01331910de7c21b73ddc0bbc91b35d66cce1 +Subproject commit 4b5bbb1158535cc9d129fd5daa6310e8404ae795 From eded2095ebd4903fe0bf6567e1ba9bd769b5d3c2 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Mon, 4 Jan 2021 09:55:04 +0000 Subject: [PATCH 06/12] Update jenkins files --- .jenkins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins b/.jenkins index 4b5bbb1..883d76e 160000 --- a/.jenkins +++ b/.jenkins @@ -1 +1 @@ -Subproject commit 4b5bbb1158535cc9d129fd5daa6310e8404ae795 +Subproject commit 883d76ec914362534813696540a119de0677525e From cfb01faf0a6be52e61b1dcff8999aa75646a0842 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sat, 16 Jan 2021 20:42:47 +0000 Subject: [PATCH 07/12] Update jenkins files --- .jenkins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins b/.jenkins index 883d76e..0452939 160000 --- a/.jenkins +++ b/.jenkins @@ -1 +1 @@ -Subproject commit 883d76ec914362534813696540a119de0677525e +Subproject commit 0452939ba9a52a318db80c2c608b26739e223ac7 From f3a89a0c2e20b719fdc4a0f38b5f2693440e094c Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sat, 16 Jan 2021 22:30:27 +0000 Subject: [PATCH 08/12] Update jenkins files --- .jenkins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins b/.jenkins index 0452939..cb399ae 160000 --- a/.jenkins +++ b/.jenkins @@ -1 +1 @@ -Subproject commit 0452939ba9a52a318db80c2c608b26739e223ac7 +Subproject commit cb399aee7bab2d69266d1b2640684f4bf0e7104c From a45e10a558d411ed616c600001c942190bf38f66 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sun, 17 Jan 2021 09:04:47 +0000 Subject: [PATCH 09/12] Update jenkins files --- .jenkins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.jenkins b/.jenkins index cb399ae..f053f46 160000 --- a/.jenkins +++ b/.jenkins @@ -1 +1 @@ -Subproject commit cb399aee7bab2d69266d1b2640684f4bf0e7104c +Subproject commit f053f468bd7ca0492355eebc15229b673484d7d9 From cfd2d988538838347715721888fba5ec97060188 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sun, 24 Jan 2021 12:39:05 +0000 Subject: [PATCH 10/12] Add logging This adds logging for content handlers so that exceptions raised by user-defined code can be immediately located. Affects: https://github.com/io7m/blackthorne/issues/3 --- README-CHANGES.xml | 15 ++++++++++++--- .../io7m/blackthorne/api/BTContentHandler.java | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README-CHANGES.xml b/README-CHANGES.xml index a613072..c7e2022 100644 --- a/README-CHANGES.xml +++ b/README-CHANGES.xml @@ -1,18 +1,27 @@ - + - + - + + + + + + + + + + diff --git a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java index 58b54bb..fe24568 100644 --- a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java +++ b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/BTContentHandler.java @@ -17,6 +17,8 @@ package com.io7m.blackthorne.api; import com.io7m.jlexing.core.LexicalPosition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.xml.sax.Attributes; import org.xml.sax.Locator; import org.xml.sax.SAXException; @@ -40,6 +42,9 @@ public final class BTContentHandler extends DefaultHandler2 { + private static final Logger LOG = + LoggerFactory.getLogger(BTContentHandler.class); + private final URI fileURI; private final Consumer errorReceiver; private Locator2 locator; @@ -112,8 +117,10 @@ private static String messageOrException( public void setDocumentLocator( final Locator in_locator) { - this.locator = (Locator2) Objects.requireNonNull(in_locator, "locator"); - this.stackHandler = new BTStackHandler(this.locator, this.rootHandlers); + this.locator = + (Locator2) Objects.requireNonNull(in_locator, "locator"); + this.stackHandler = + new BTStackHandler<>(this.locator, this.rootHandlers); } @Override @@ -166,6 +173,8 @@ public void characters( public void warning( final SAXParseException e) { + LOG.warn("parse exception: ", e); + this.errorReceiver.accept( BTParseError.builder() .setException(e) @@ -179,6 +188,8 @@ public void warning( public void error( final SAXParseException e) { + LOG.error("parse exception: ", e); + this.failed = true; this.errorReceiver.accept( BTParseError.builder() @@ -194,6 +205,8 @@ public void fatalError( final SAXParseException e) throws SAXException { + LOG.error("fatal parse exception: ", e); + this.failed = true; this.errorReceiver.accept( BTParseError.builder() From 0cc1b8b37e38a8d18a8df21cd81c7b607f0efba3 Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sun, 24 Jan 2021 12:57:09 +0000 Subject: [PATCH 11/12] Add more scalar element handlers This adds more scalar element handlers to the Blackthorne API to make it more convenient to parse text values from elements. Affects: https://github.com/io7m/blackthorne/issues/2 --- README-CHANGES.xml | 9 +- com.io7m.blackthorne.api/pom.xml | 2 +- .../com/io7m/blackthorne/api/Blackthorne.java | 81 ++++++++++++ .../io7m/blackthorne/api/package-info.java | 2 +- com.io7m.blackthorne.jxe/pom.xml | 2 +- com.io7m.blackthorne.tests/pom.xml | 2 +- .../blackthorne/tests/BlackthorneTest.java | 119 ++++++++++++++++++ .../com/io7m/blackthorne/tests/choice.xsd | 6 + .../com/io7m/blackthorne/tests/string.xml | 3 + pom.xml | 4 +- 10 files changed, 222 insertions(+), 8 deletions(-) create mode 100644 com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/string.xml diff --git a/README-CHANGES.xml b/README-CHANGES.xml index c7e2022..e2c3423 100644 --- a/README-CHANGES.xml +++ b/README-CHANGES.xml @@ -13,13 +13,18 @@ - + - + + + + + + diff --git a/com.io7m.blackthorne.api/pom.xml b/com.io7m.blackthorne.api/pom.xml index 5347e8c..615bfc0 100644 --- a/com.io7m.blackthorne.api/pom.xml +++ b/com.io7m.blackthorne.api/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT com.io7m.blackthorne.api diff --git a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/Blackthorne.java b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/Blackthorne.java index 3024ae9..9826549 100644 --- a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/Blackthorne.java +++ b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/Blackthorne.java @@ -276,6 +276,87 @@ public static BTElementHandlerConstructorType> forListPoly( ignoreUnrecognized); } + /** + * A convenience function for constructing content handlers that produce a scalar value from the + * text content of a single XML element. + * + * @param elementName The name of the element + * + * @return A content handler constructor + */ + + public static BTElementHandlerConstructorType forScalarString( + final BTQualifiedName elementName) + { + return forScalar(elementName, (context, characters, offset, length) -> { + // CHECKSTYLE:OFF + return new String(characters, offset, length); + // CHECKSTYLE:ON + }); + } + + /** + * A convenience function for constructing content handlers that produce a scalar value from the + * text content of a single XML element. + * + * @param namespaceURI The namespace of the element + * @param localName The local element name + * + * @return A content handler constructor + */ + + public static BTElementHandlerConstructorType forScalarString( + final String namespaceURI, + final String localName) + { + return forScalar( + namespaceURI, + localName, + (context, characters, offset, length) -> { + // CHECKSTYLE:OFF + return new String(characters, offset, length); + // CHECKSTYLE:ON + }); + } + + /** + * A convenience function for constructing content handlers that produce a scalar value from the + * text content of a single XML element. + * + * @param elementName The name of the element + * @param parser A function from strings to values of type {@code S} + * @param The type of returned values + * + * @return A content handler constructor + */ + + public static BTElementHandlerConstructorType forScalarFromString( + final BTQualifiedName elementName, + final Function parser) + { + return mapConstructor(forScalarString(elementName), parser); + } + + /** + * A convenience function for constructing content handlers that produce a scalar value from the + * text content of a single XML element. + * + * @param namespaceURI The namespace of the element + * @param localName The local element name + * @param parser A function from strings to values of type {@code S} + * @param The type of returned values + * + * @return A content handler constructor + */ + + public static BTElementHandlerConstructorType forScalarFromString( + final String namespaceURI, + final String localName, + final Function parser) + { + return mapConstructor(forScalarString(namespaceURI, localName), parser); + } + /** * A convenience method to configure and execute a parser. * diff --git a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/package-info.java b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/package-info.java index 81fbddc..7fa8a09 100644 --- a/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/package-info.java +++ b/com.io7m.blackthorne.api/src/main/java/com/io7m/blackthorne/api/package-info.java @@ -19,7 +19,7 @@ */ @Export -@Version("1.1.0") +@Version("1.2.0") package com.io7m.blackthorne.api; import org.osgi.annotation.bundle.Export; diff --git a/com.io7m.blackthorne.jxe/pom.xml b/com.io7m.blackthorne.jxe/pom.xml index 6b069a2..6ef07dc 100644 --- a/com.io7m.blackthorne.jxe/pom.xml +++ b/com.io7m.blackthorne.jxe/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT com.io7m.blackthorne.jxe diff --git a/com.io7m.blackthorne.tests/pom.xml b/com.io7m.blackthorne.tests/pom.xml index 9baf51e..24699f2 100644 --- a/com.io7m.blackthorne.tests/pom.xml +++ b/com.io7m.blackthorne.tests/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT com.io7m.blackthorne.tests diff --git a/com.io7m.blackthorne.tests/src/test/java/com/io7m/blackthorne/tests/BlackthorneTest.java b/com.io7m.blackthorne.tests/src/test/java/com/io7m/blackthorne/tests/BlackthorneTest.java index 1580929..811d64a 100644 --- a/com.io7m.blackthorne.tests/src/test/java/com/io7m/blackthorne/tests/BlackthorneTest.java +++ b/com.io7m.blackthorne.tests/src/test/java/com/io7m/blackthorne/tests/BlackthorneTest.java @@ -1278,4 +1278,123 @@ public void testLeafIntegerAttr0() Assertions.assertEquals(0, this.errors.size()); Assertions.assertEquals(BigInteger.valueOf(23L), handler.result().get()); } + + /** + * Scalar element handlers work. + * + * @throws Exception On errors + */ + + @Test + public void testText0() + throws Exception + { + final var handler = + BTContentHandler.builder() + .addHandler( + "urn:tests", + "string", + Blackthorne.forScalarString("urn:tests", "string")) + .build(URI.create("urn:text"), this::logError); + + final var reader = createReader(); + reader.setContentHandler(handler); + reader.setErrorHandler(handler); + reader.parse(resource("string.xml")); + + Assertions.assertFalse(handler.failed()); + Assertions.assertEquals(0, this.errors.size()); + Assertions.assertEquals("This is some text.", handler.result().get()); + } + + /** + * Scalar element handlers work. + * + * @throws Exception On errors + */ + + @Test + public void testText1() + throws Exception + { + final var name = + BTQualifiedName.of("urn:tests", "string"); + + final var handler = + BTContentHandler.builder() + .addHandler(name, Blackthorne.forScalarString(name)) + .build(URI.create("urn:text"), this::logError); + + final var reader = createReader(); + reader.setContentHandler(handler); + reader.setErrorHandler(handler); + reader.parse(resource("string.xml")); + + Assertions.assertFalse(handler.failed()); + Assertions.assertEquals(0, this.errors.size()); + Assertions.assertEquals("This is some text.", handler.result().get()); + } + + /** + * Scalar element handlers work. + * + * @throws Exception On errors + */ + + @Test + public void testText2() + throws Exception + { + final var handler = + BTContentHandler.builder() + .addHandler( + "urn:tests", + "string", + Blackthorne.forScalarFromString( + "urn:tests", + "string", + Exception::new)) + .build(URI.create("urn:text"), this::logError); + + final var reader = createReader(); + reader.setContentHandler(handler); + reader.setErrorHandler(handler); + reader.parse(resource("string.xml")); + + Assertions.assertFalse(handler.failed()); + Assertions.assertEquals(0, this.errors.size()); + Assertions.assertEquals( + "This is some text.", + handler.result().get().getMessage()); + } + + /** + * Scalar element handlers work. + * + * @throws Exception On errors + */ + + @Test + public void testText3() + throws Exception + { + final var name = + BTQualifiedName.of("urn:tests", "string"); + + final var handler = + BTContentHandler.builder() + .addHandler(name, Blackthorne.forScalarFromString(name, Exception::new)) + .build(URI.create("urn:text"), this::logError); + + final var reader = createReader(); + reader.setContentHandler(handler); + reader.setErrorHandler(handler); + reader.parse(resource("string.xml")); + + Assertions.assertFalse(handler.failed()); + Assertions.assertEquals(0, this.errors.size()); + Assertions.assertEquals( + "This is some text.", + handler.result().get().getMessage()); + } } diff --git a/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/choice.xsd b/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/choice.xsd index fe87c61..fd2e9a6 100644 --- a/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/choice.xsd +++ b/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/choice.xsd @@ -5,6 +5,12 @@ attributeFormDefault="qualified" targetNamespace="urn:tests"> + + + + + + diff --git a/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/string.xml b/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/string.xml new file mode 100644 index 0000000..5048ee2 --- /dev/null +++ b/com.io7m.blackthorne.tests/src/test/resources/com/io7m/blackthorne/tests/string.xml @@ -0,0 +1,3 @@ + + +This is some text. diff --git a/pom.xml b/pom.xml index 9a916ed..5f45004 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.1.1-SNAPSHOT + 1.2.0-SNAPSHOT pom com.io7m.blackthorne @@ -33,7 +33,7 @@ 2.7.5 5.7.0 1.0.0 - 1.0.0 + 1.1.0 From a4bc8521c610613ce226b5535915147826fff39a Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Sun, 24 Jan 2021 13:01:39 +0000 Subject: [PATCH 12/12] Mark 1.2.0 --- README-CHANGES.xml | 4 ++-- com.io7m.blackthorne.api/pom.xml | 2 +- com.io7m.blackthorne.jxe/pom.xml | 2 +- com.io7m.blackthorne.tests/pom.xml | 2 +- pom.xml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README-CHANGES.xml b/README-CHANGES.xml index e2c3423..ff04ee7 100644 --- a/README-CHANGES.xml +++ b/README-CHANGES.xml @@ -13,14 +13,14 @@ - + - + diff --git a/com.io7m.blackthorne.api/pom.xml b/com.io7m.blackthorne.api/pom.xml index 615bfc0..d4eef54 100644 --- a/com.io7m.blackthorne.api/pom.xml +++ b/com.io7m.blackthorne.api/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.2.0-SNAPSHOT + 1.2.0 com.io7m.blackthorne.api diff --git a/com.io7m.blackthorne.jxe/pom.xml b/com.io7m.blackthorne.jxe/pom.xml index 6ef07dc..5bfe797 100644 --- a/com.io7m.blackthorne.jxe/pom.xml +++ b/com.io7m.blackthorne.jxe/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.2.0-SNAPSHOT + 1.2.0 com.io7m.blackthorne.jxe diff --git a/com.io7m.blackthorne.tests/pom.xml b/com.io7m.blackthorne.tests/pom.xml index 24699f2..f73036b 100644 --- a/com.io7m.blackthorne.tests/pom.xml +++ b/com.io7m.blackthorne.tests/pom.xml @@ -8,7 +8,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.2.0-SNAPSHOT + 1.2.0 com.io7m.blackthorne.tests diff --git a/pom.xml b/pom.xml index 5f45004..91cdece 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ com.io7m.blackthorne com.io7m.blackthorne - 1.2.0-SNAPSHOT + 1.2.0 pom com.io7m.blackthorne