From 3e6d7306ded92522912fa247cf229edc70db46c1 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Wed, 25 Dec 2024 12:46:23 +0300 Subject: [PATCH 1/2] bug(#3726): Updated jcabi-xml and made StrictXmir synchronized --- .../java/org/eolang/parser/StrictXmir.java | 40 ++++++++++-------- .../src/main/java/org/eolang/parser/Xmir.java | 5 ++- .../java/org/eolang/parser/DrProgramTest.java | 24 ++++++----- .../org/eolang/parser/StrictXmirTest.java | 28 ++++++------- pom.xml | 41 +++++++++++++++++++ 5 files changed, 95 insertions(+), 43 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java b/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java index 5d0eaca558..a91d450dc6 100644 --- a/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java +++ b/eo-parser/src/main/java/org/eolang/parser/StrictXmir.java @@ -41,7 +41,11 @@ import org.cactoos.bytes.IoCheckedBytes; import org.cactoos.io.InputOf; import org.cactoos.io.ResourceOf; +import org.cactoos.scalar.Sticky; +import org.cactoos.scalar.Synced; +import org.cactoos.scalar.Unchecked; import org.w3c.dom.Node; +import org.w3c.dom.ls.LSResourceResolver; import org.xembly.Directives; import org.xembly.Xembler; import org.xml.sax.SAXParseException; @@ -71,7 +75,7 @@ public final class StrictXmir implements XML { /** * The XML. */ - private final XML xml; + private final Unchecked xml; /** * Ctor. @@ -91,36 +95,40 @@ public StrictXmir(final XML src) { */ @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") public StrictXmir(final XML before, final Path tmp) { - synchronized (before) { - this.xml = new StrictXML( - StrictXmir.reset(before, tmp) - ); - } + this.xml = new Unchecked<>( + new Synced<>( + new Sticky<>( + () -> new StrictXML( + StrictXmir.reset(before, tmp) + ) + ) + ) + ); } @Override public String toString() { - return this.xml.toString(); + return this.xml.value().toString(); } @Override public List xpath(final String query) { - return this.xml.xpath(query); + return this.xml.value().xpath(query); } @Override public List nodes(final String query) { - return this.xml.nodes(query); + return this.xml.value().nodes(query); } @Override public XML registerNs(final String prefix, final Object uri) { - return this.xml.registerNs(prefix, uri); + return this.xml.value().registerNs(prefix, uri); } @Override public XML merge(final NamespaceContext context) { - return this.xml.merge(context); + return this.xml.value().merge(context); } @Override @@ -131,22 +139,22 @@ public Node node() { @Override public Node inner() { - return this.xml.inner(); + return this.xml.value().inner(); } @Override public Node deepCopy() { - return this.xml.deepCopy(); + return this.xml.value().deepCopy(); } @Override - public Collection validate() { - return this.xml.validate(); + public Collection validate(final LSResourceResolver resolver) { + return this.xml.value().validate(resolver); } @Override public Collection validate(final XML schema) { - return this.xml.validate(schema); + return this.xml.value().validate(schema); } /** diff --git a/eo-parser/src/main/java/org/eolang/parser/Xmir.java b/eo-parser/src/main/java/org/eolang/parser/Xmir.java index 6360f1d87f..ac06160b48 100644 --- a/eo-parser/src/main/java/org/eolang/parser/Xmir.java +++ b/eo-parser/src/main/java/org/eolang/parser/Xmir.java @@ -39,6 +39,7 @@ import java.util.logging.Level; import javax.xml.namespace.NamespaceContext; import org.w3c.dom.Node; +import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.SAXParseException; /** @@ -163,8 +164,8 @@ public Node deepCopy() { } @Override - public Collection validate() { - return this.xml.validate(); + public Collection validate(final LSResourceResolver resolver) { + return this.xml.validate(resolver); } @Override diff --git a/eo-parser/src/test/java/org/eolang/parser/DrProgramTest.java b/eo-parser/src/test/java/org/eolang/parser/DrProgramTest.java index 653e94e57c..dd606a973d 100644 --- a/eo-parser/src/test/java/org/eolang/parser/DrProgramTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/DrProgramTest.java @@ -24,11 +24,13 @@ package org.eolang.parser; import com.jcabi.matchers.XhtmlMatchers; +import com.jcabi.xml.StrictXML; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; import java.nio.file.Paths; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; @@ -83,17 +85,17 @@ void setsSchemaLocation() throws Exception { @Test void validatesAgainstSchema() { - MatcherAssert.assertThat( - "XMIR document validates correctly", - new XMLDocument( - new Xembler( - new Directives().append(new DrProgram("foo")) - .add("listing").set("hello, world!").up() - .add("objects").add("o").attr("name", "bar") - ).domQuietly() - ).validate(), - Matchers.emptyIterable() + Assertions.assertDoesNotThrow( + new StrictXML( + new XMLDocument( + new Xembler( + new Directives().append(new DrProgram("foo")) + .add("listing").set("hello, world!").up() + .add("objects").add("o").attr("name", "bar") + ).domQuietly() + ) + )::inner, + "XMIR document validates correctly" ); } - } diff --git a/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java b/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java index 155edb6db9..6a5dc80745 100644 --- a/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java +++ b/eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java @@ -52,13 +52,12 @@ final class StrictXmirTest { @ExtendWith(MktmpResolver.class) @ExtendWith(WeAreOnline.class) void validatesXmir(@Mktmp final Path tmp) { - MatcherAssert.assertThat( - "validation should pass as normal", + Assertions.assertDoesNotThrow( new StrictXmir( StrictXmirTest.xmir("https://www.eolang.org/XMIR.xsd"), tmp - ).validate(), - Matchers.emptyIterable() + )::inner, + "validation should pass as normal" ); MatcherAssert.assertThat( "temporary XSD file created", @@ -75,7 +74,7 @@ void doesNotFailWithDifferentXmlInMultipleThreads(@Mktmp final Path tmp) { new Together<>( thread -> { final XML xml = StrictXmirTest.xmir("https://www.eolang.org/XMIR.xsd"); - return new StrictXmir(xml, tmp); + return new StrictXmir(xml, tmp).inner(); } )::asList, "StrictXmir should not fail in different threads with different xmls" @@ -85,11 +84,13 @@ void doesNotFailWithDifferentXmlInMultipleThreads(@Mktmp final Path tmp) { @RepeatedTest(20) @ExtendWith(WeAreOnline.class) @ExtendWith(MktmpResolver.class) - void doesNotFailWithSameXmlInMultipleThreads(@Mktmp final Path tmp) { - final XML xml = StrictXmirTest.xmir("https://www.eolang.org/XMIR.xsd"); + void doesNotFailOnTheSameOperation(@Mktmp final Path tmp) { + final XML xmir = new StrictXmir( + StrictXmirTest.xmir("https://www.eolang.org/XMIR.xsd"), tmp + ); Assertions.assertDoesNotThrow( new Together<>( - thread -> new StrictXmir(xml, tmp) + thread -> xmir.inner() )::asList, "StrictXmir should not fail in different threads with the same xml" ); @@ -114,8 +115,7 @@ void refersToAbsoluteFileName(@Mktmp final Path tmp) { @Test @ExtendWith(MktmpResolver.class) void validatesXmirWithLocalSchema(@Mktmp final Path tmp) { - MatcherAssert.assertThat( - "validation should pass as normal", + Assertions.assertDoesNotThrow( new StrictXmir( new Xmir( StrictXmirTest.xmir( @@ -126,8 +126,8 @@ void validatesXmirWithLocalSchema(@Mktmp final Path tmp) { ) ), tmp - ).validate(), - Matchers.emptyIterable() + )::inner, + "validation should pass as normal" ); MatcherAssert.assertThat( "temporary XSD file created", @@ -143,12 +143,12 @@ void validatesXmirWithLocalSchema(@Mktmp final Path tmp) { void validatesXmirWithBrokenUri(@Mktmp final Path tmp) { Assertions.assertThrows( IllegalArgumentException.class, - () -> new StrictXmir( + new StrictXmir( new Xmir( StrictXmirTest.xmir("https://www.invalid-website-uri/XMIR.xsd") ), tmp - ).validate(), + )::inner, "validation should fail because of broken URI" ); } diff --git a/pom.xml b/pom.xml index 33683cfd5e..a562b576e5 100644 --- a/pom.xml +++ b/pom.xml @@ -205,7 +205,11 @@ SOFTWARE. com.jcabi jcabi-xml +<<<<<<< Updated upstream 0.33.1 +======= + 0.33.3 +>>>>>>> Stashed changes com.jcabi @@ -321,6 +325,43 @@ SOFTWARE. +<<<<<<< Updated upstream +======= + + org.codehaus.gmaven + groovy-maven-plugin + 2.1.1 + + + project-validate + validate + + execute + + + ${project.basedir}/src/test/groovy/verify.groovy + + + + + + com.jcabi + jcabi-xml + 0.33.3 + + + org.codehaus.groovy + groovy-xml + 3.0.23 + + + net.sf.saxon + Saxon-HE + 12.5 + + + +>>>>>>> Stashed changes From b408f9b9a4b7fcb89bfb15126bf7f51e0ba2d356 Mon Sep 17 00:00:00 2001 From: maxonfjvipon Date: Wed, 25 Dec 2024 12:57:14 +0300 Subject: [PATCH 2/2] bug(#3726): Fixed pom --- pom.xml | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/pom.xml b/pom.xml index a562b576e5..31823b2cfc 100644 --- a/pom.xml +++ b/pom.xml @@ -205,11 +205,7 @@ SOFTWARE. com.jcabi jcabi-xml -<<<<<<< Updated upstream - 0.33.1 -======= 0.33.3 ->>>>>>> Stashed changes com.jcabi @@ -325,43 +321,6 @@ SOFTWARE. -<<<<<<< Updated upstream -======= - - org.codehaus.gmaven - groovy-maven-plugin - 2.1.1 - - - project-validate - validate - - execute - - - ${project.basedir}/src/test/groovy/verify.groovy - - - - - - com.jcabi - jcabi-xml - 0.33.3 - - - org.codehaus.groovy - groovy-xml - 3.0.23 - - - net.sf.saxon - Saxon-HE - 12.5 - - - ->>>>>>> Stashed changes @@ -523,7 +482,7 @@ SOFTWARE. com.jcabi jcabi-xml - 0.33.1 + 0.33.3 org.codehaus.groovy