Skip to content

Commit

Permalink
#182 qulice 0.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 28, 2022
1 parent 3fd726e commit e8438b9
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 106 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -101,7 +101,6 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<!-- don't change it, leave at 1.4.01 -->
<version>2.0.2</version>
<scope>provided</scope>
</dependency>
Expand All @@ -113,7 +112,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<artifactId>slf4j-reload4j</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
Expand Down Expand Up @@ -162,10 +161,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<plugin>
<groupId>com.qulice</groupId>
<artifactId>qulice-maven-plugin</artifactId>
<version>0.21.1</version>
<version>0.22.0</version>
<configuration>
<excludes combine.children="append">
<exclude>xml:/src/it/settings.xml</exclude>
<exclude>pmd:/src/it/.*</exclude>
<exclude>xml:/src/test/resources/com/jcabi/xml/.*</exclude>
<exclude>findbugs:.*</exclude>
</excludes>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/jcabi/xml/DomParser.java
Expand Up @@ -113,6 +113,7 @@ public Document document() {
ex
);
}
final long start = System.nanoTime();
final Document doc;
try {
doc = builder.parse(new ByteArrayInputStream(this.xml));
Expand All @@ -126,7 +127,13 @@ public Document document() {
);
}
if (Logger.isDebugEnabled(this)) {
Logger.debug(this, "%s parsed XML", builder.getClass().getName());
Logger.debug(
this,
"%s parsed %d bytes of XML in %[nano]s",
builder.getClass().getName(),
this.xml.length,
System.nanoTime() - start
);
}
return doc;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/jcabi/xml/XMLDocument.java
Expand Up @@ -337,7 +337,7 @@ public int hashCode() {

@Override
public Node node() {
final Node casted = Node.class.cast(this.cache);
final Node casted = this.cache;
final Node answer;
if (casted instanceof Document) {
answer = casted.cloneNode(true);
Expand All @@ -362,7 +362,7 @@ public List<String> xpath(final String query) {
final NodeList nodes = this.fetch(query, NodeList.class);
items = new ArrayList<>(nodes.getLength());
for (int idx = 0; idx < nodes.getLength(); ++idx) {
final int type = (int) nodes.item(idx).getNodeType();
final int type = nodes.item(idx).getNodeType();
if (type != (int) Node.TEXT_NODE
&& type != (int) Node.ATTRIBUTE_NODE
&& type != (int) Node.CDATA_SECTION_NODE) {
Expand Down Expand Up @@ -391,13 +391,13 @@ public List<String> xpath(final String query) {
);
}
}
return new ListWrapper<>(items, Node.class.cast(this.cache), query);
return new ListWrapper<>(items, this.cache, query);
}

@Override
public XML registerNs(final String prefix, final Object uri) {
return new XMLDocument(
Node.class.cast(this.cache),
this.cache,
this.context.add(prefix, uri),
this.leaf
);
Expand Down Expand Up @@ -425,13 +425,13 @@ public List<XML> nodes(final String query) {
), ex
);
}
return new ListWrapper<>(items, Node.class.cast(this.cache), query);
return new ListWrapper<>(items, this.cache, query);
}

@Override
public XML merge(final NamespaceContext ctx) {
return new XMLDocument(
Node.class.cast(this.cache),
this.cache,
this.context.merge(ctx),
this.leaf
);
Expand Down Expand Up @@ -496,7 +496,7 @@ private <T> T fetch(final String query, final Class<T> type)
)
);
}
return (T) xpath.evaluate(query, Node.class.cast(this.cache), qname);
return (T) xpath.evaluate(query, this.cache, qname);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jcabi/xml/XSDDocument.java
Expand Up @@ -184,14 +184,14 @@ public Collection<SAXParseException> validate(final Source xml) {
}
} catch (final SAXException ex) {
throw new IllegalStateException(
String.format("failed to create XSD schema from %s", this.xsd),
String.format("Failed to create XSD schema from %s", this.xsd),
ex
);
}
final Collection<SAXParseException> errors =
new CopyOnWriteArrayList<>();
final Validator validator = schema.newValidator();
validator.setErrorHandler(new ValidationHandler(errors));
validator.setErrorHandler(new XSDDocument.ValidationHandler(errors));
try {
synchronized (XSDDocument.class) {
validator.validate(xml);
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/jcabi/xml/XSLDocument.java
Expand Up @@ -83,7 +83,7 @@ public final class XSLDocument implements XSL {
*
* <p>This will NOT remove
* existing indentation between Element nodes currently introduced by the
* constructor of {@link com.jcabi.xml.XMLDocument}. For example:
* constructor of {@link XMLDocument}. For example:
*
* <pre>
* {@code
Expand Down Expand Up @@ -403,6 +403,7 @@ private void transformInto(final XML xml, final Result result) {
final Transformer trans = this.transformer();
final ConsoleErrorListener errors = new ConsoleErrorListener();
trans.setErrorListener(errors);
final long start = System.nanoTime();
try {
trans.transform(new DOMSource(xml.node()), result);
} catch (final TransformerException ex) {
Expand All @@ -416,7 +417,12 @@ private void transformInto(final XML xml, final Result result) {
);
}
if (Logger.isDebugEnabled(this)) {
Logger.debug(this, "%s transformed XML", trans.getClass().getName());
Logger.debug(
this,
"%s transformed XML in %[nano]s",
trans.getClass().getName(),
System.nanoTime() - start
);
}
}

Expand Down Expand Up @@ -464,12 +470,12 @@ private static Transformer forSaxon(final Transformer trans) {
return trans;
}
if (Version.getStructuredVersionNumber()[0] < 11) {
TransformerImpl.class.cast(trans)
((TransformerImpl) trans)
.getUnderlyingController()
.setMessageEmitter(new MessageWarner());
}
if (Version.getStructuredVersionNumber()[0] >= 11) {
TransformerImpl.class.cast(trans)
((TransformerImpl) trans)
.getUnderlyingController()
.setMessageHandler(
message -> Logger.error(
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/jcabi/xml/ClasspathInputTest.java
Expand Up @@ -35,12 +35,12 @@
import org.w3c.dom.ls.LSInput;

/**
* Test case for {@link com.jcabi.xml.ClasspathInput}.
* Test case for {@link ClasspathInput}.
* @since 0.17.3
*/
public final class ClasspathInputTest {
final class ClasspathInputTest {
@Test
public void readsStringFromResourceSuccessfully() {
void readsStringFromResourceSuccessfully() {
final LSInput input = new ClasspathInput(
"Id", "com/jcabi/xml/simple.xml"
);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/jcabi/xml/ClasspathSourcesTest.java
Expand Up @@ -37,10 +37,10 @@
* Test of ClasspathSources.
* @since 0.18
*/
public final class ClasspathSourcesTest {
final class ClasspathSourcesTest {

@Test
public void sourcesResolvedFromBase() throws Exception {
void sourcesResolvedFromBase() throws Exception {
MatcherAssert.assertThat(
new ClasspathSources().resolve("simple.xml", "com.jcabi.xml."),
Matchers.notNullValue()
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/jcabi/xml/DomParserTest.java
Expand Up @@ -38,10 +38,10 @@
* Test case for {@link DomParser}.
* @since 0.1
*/
public final class DomParserTest {
final class DomParserTest {

@Test
public void parsesIncomingXmlDocument() {
void parsesIncomingXmlDocument() {
final String xml = "<a><b>\u0443\u0440\u0430!</b></a>";
final DomParser parser = new DomParser(
DocumentBuilderFactory.newInstance(), xml
Expand All @@ -53,7 +53,7 @@ public void parsesIncomingXmlDocument() {
}

@Test
public void parsesIncomingXmlDocumentComment() {
void parsesIncomingXmlDocumentComment() {
final String xml = "<?xml version='1.0'?><!-- test --><root/>";
final DomParser parser = new DomParser(
DocumentBuilderFactory.newInstance(), xml
Expand All @@ -66,8 +66,8 @@ public void parsesIncomingXmlDocumentComment() {

@Test
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public void allowsValidXmlFormatting() {
final String[] texts = new String[] {
void allowsValidXmlFormatting() {
final String[] texts = {
"<?xml version=\"1.0\" encoding='ISO-8895-1'?><a/>",
"<:a/>",
"<ns:a><ns2:test-me/></ns:a>",
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/jcabi/xml/FileSourcesTest.java
Expand Up @@ -41,10 +41,10 @@
* Test of FileSources.
* @since 0.18
*/
public final class FileSourcesTest {
final class FileSourcesTest {

@Test
public void sourcesResolvedFromDir() throws Exception {
void sourcesResolvedFromDir() throws Exception {
final File file = Files.createTempDirectory("")
.resolve("dummy.xml").toFile();
new LengthOf(new TeeInput("test", file)).value();
Expand Down
25 changes: 13 additions & 12 deletions src/test/java/com/jcabi/xml/StrictXMLTest.java
Expand Up @@ -50,6 +50,7 @@
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;

Expand All @@ -61,17 +62,17 @@
* @checkstyle AbbreviationAsWordInNameCheck (5 lines)
*/
@SuppressWarnings({ "PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"})
public final class StrictXMLTest {
final class StrictXMLTest {

@BeforeEach
public void weAreOnline() throws IOException {
void weAreOnline() throws IOException {
Assumptions.assumeTrue(
InetAddress.getByName("w3.org").isReachable(1000)
);
}

@Test
public void passesValidXmlThrough() {
void passesValidXmlThrough() {
new StrictXML(
new XMLDocument("<root>passesValidXmlThrough</root>"),
new XSDDocument(
Expand All @@ -85,7 +86,7 @@ public void passesValidXmlThrough() {
}

@Test
public void rejectsInvalidXmlThrough() {
void rejectsInvalidXmlThrough() {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> new StrictXML(
Expand All @@ -101,7 +102,7 @@ public void rejectsInvalidXmlThrough() {
}

@Test
public void passesValidXmlUsingXsiSchemaLocation() throws Exception {
void passesValidXmlUsingXsiSchemaLocation() throws Exception {
new StrictXML(
new XMLDocument(
this.getClass().getResource("xsi-schemalocation-valid.xml")
Expand All @@ -110,7 +111,7 @@ public void passesValidXmlUsingXsiSchemaLocation() throws Exception {
}

@Test
public void rejectsInvalidXmlUsingXsiSchemaLocation() {
void rejectsInvalidXmlUsingXsiSchemaLocation() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new StrictXML(
Expand All @@ -122,7 +123,7 @@ public void rejectsInvalidXmlUsingXsiSchemaLocation() {
}

@Test
public void validatesMultipleXmlsInThreads() throws Exception {
void validatesMultipleXmlsInThreads() throws Exception {
final int timeout = 10;
final int numrun = 100;
final int loop = 50;
Expand Down Expand Up @@ -176,7 +177,7 @@ public void validatesMultipleXmlsInThreads() throws Exception {
}

@Test
public void passesValidXmlWithNetworkProblems() throws Exception {
void passesValidXmlWithNetworkProblems() throws Exception {
final Validator validator = Mockito.mock(Validator.class);
final AtomicInteger counter = new AtomicInteger(0);
// @checkstyle IllegalThrowsCheck (5 lines)
Expand All @@ -190,7 +191,7 @@ public void passesValidXmlWithNetworkProblems() throws Exception {
}
return null;
}
).when(validator).validate(Mockito.any(Source.class));
).when(validator).validate(ArgumentMatchers.any(Source.class));
new StrictXML(
new XMLDocument(
"<root>passesValidXmlWithNetworkProblems</root>"
Expand All @@ -200,7 +201,7 @@ public void passesValidXmlWithNetworkProblems() throws Exception {
}

@Test
public void lookupXsdsFromClasspath() {
void lookupXsdsFromClasspath() {
new StrictXML(
new XMLDocument(
StringUtils.join(
Expand All @@ -224,7 +225,7 @@ public void lookupXsdsFromClasspath() {
}

@Test
public void rejectXmlWhenXsdIsNotAvailableOnClasspath() {
void rejectXmlWhenXsdIsNotAvailableOnClasspath() {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> new StrictXML(
Expand All @@ -251,7 +252,7 @@ public void rejectXmlWhenXsdIsNotAvailableOnClasspath() {
}

@Test
public void handlesXmlWithoutSchemaLocation() {
void handlesXmlWithoutSchemaLocation() {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> new StrictXML(
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/jcabi/xml/TextResourceTest.java
Expand Up @@ -45,10 +45,10 @@
*
* @since 0.1
*/
public final class TextResourceTest {
final class TextResourceTest {

@Test
public void readsStreamAsText() {
void readsStreamAsText() {
final String text = "Blah!\u20ac\u2122";
final InputStream stream = new ByteArrayInputStream(
text.getBytes(StandardCharsets.UTF_8)
Expand All @@ -60,7 +60,7 @@ public void readsStreamAsText() {
}

@Test
public void readsFileAsText() throws Exception {
void readsFileAsText() throws Exception {
final String text = "<a xmlns='urn:foo'><b>\u0433!</b></a>";
final File file = Files.createTempDirectory("")
.resolve("dummy.xml").toFile();
Expand Down

0 comments on commit e8438b9

Please sign in to comment.