Skip to content

Commit e8438b9

Browse files
committed
#182 qulice 0.22.0
1 parent 3fd726e commit e8438b9

16 files changed

Lines changed: 108 additions & 106 deletions

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
101101
<dependency>
102102
<groupId>xml-apis</groupId>
103103
<artifactId>xml-apis</artifactId>
104-
<!-- don't change it, leave at 1.4.01 -->
105104
<version>2.0.2</version>
106105
<scope>provided</scope>
107106
</dependency>
@@ -113,7 +112,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
113112
</dependency>
114113
<dependency>
115114
<groupId>org.slf4j</groupId>
116-
<artifactId>slf4j-log4j12</artifactId>
115+
<artifactId>slf4j-reload4j</artifactId>
117116
<version>2.0.2</version>
118117
<scope>test</scope>
119118
</dependency>
@@ -162,10 +161,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
162161
<plugin>
163162
<groupId>com.qulice</groupId>
164163
<artifactId>qulice-maven-plugin</artifactId>
165-
<version>0.21.1</version>
164+
<version>0.22.0</version>
166165
<configuration>
167166
<excludes combine.children="append">
168167
<exclude>xml:/src/it/settings.xml</exclude>
168+
<exclude>pmd:/src/it/.*</exclude>
169169
<exclude>xml:/src/test/resources/com/jcabi/xml/.*</exclude>
170170
<exclude>findbugs:.*</exclude>
171171
</excludes>

src/main/java/com/jcabi/xml/DomParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public Document document() {
113113
ex
114114
);
115115
}
116+
final long start = System.nanoTime();
116117
final Document doc;
117118
try {
118119
doc = builder.parse(new ByteArrayInputStream(this.xml));
@@ -126,7 +127,13 @@ public Document document() {
126127
);
127128
}
128129
if (Logger.isDebugEnabled(this)) {
129-
Logger.debug(this, "%s parsed XML", builder.getClass().getName());
130+
Logger.debug(
131+
this,
132+
"%s parsed %d bytes of XML in %[nano]s",
133+
builder.getClass().getName(),
134+
this.xml.length,
135+
System.nanoTime() - start
136+
);
130137
}
131138
return doc;
132139
}

src/main/java/com/jcabi/xml/XMLDocument.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public int hashCode() {
337337

338338
@Override
339339
public Node node() {
340-
final Node casted = Node.class.cast(this.cache);
340+
final Node casted = this.cache;
341341
final Node answer;
342342
if (casted instanceof Document) {
343343
answer = casted.cloneNode(true);
@@ -362,7 +362,7 @@ public List<String> xpath(final String query) {
362362
final NodeList nodes = this.fetch(query, NodeList.class);
363363
items = new ArrayList<>(nodes.getLength());
364364
for (int idx = 0; idx < nodes.getLength(); ++idx) {
365-
final int type = (int) nodes.item(idx).getNodeType();
365+
final int type = nodes.item(idx).getNodeType();
366366
if (type != (int) Node.TEXT_NODE
367367
&& type != (int) Node.ATTRIBUTE_NODE
368368
&& type != (int) Node.CDATA_SECTION_NODE) {
@@ -391,13 +391,13 @@ public List<String> xpath(final String query) {
391391
);
392392
}
393393
}
394-
return new ListWrapper<>(items, Node.class.cast(this.cache), query);
394+
return new ListWrapper<>(items, this.cache, query);
395395
}
396396

397397
@Override
398398
public XML registerNs(final String prefix, final Object uri) {
399399
return new XMLDocument(
400-
Node.class.cast(this.cache),
400+
this.cache,
401401
this.context.add(prefix, uri),
402402
this.leaf
403403
);
@@ -425,13 +425,13 @@ public List<XML> nodes(final String query) {
425425
), ex
426426
);
427427
}
428-
return new ListWrapper<>(items, Node.class.cast(this.cache), query);
428+
return new ListWrapper<>(items, this.cache, query);
429429
}
430430

431431
@Override
432432
public XML merge(final NamespaceContext ctx) {
433433
return new XMLDocument(
434-
Node.class.cast(this.cache),
434+
this.cache,
435435
this.context.merge(ctx),
436436
this.leaf
437437
);
@@ -496,7 +496,7 @@ private <T> T fetch(final String query, final Class<T> type)
496496
)
497497
);
498498
}
499-
return (T) xpath.evaluate(query, Node.class.cast(this.cache), qname);
499+
return (T) xpath.evaluate(query, this.cache, qname);
500500
}
501501

502502
/**

src/main/java/com/jcabi/xml/XSDDocument.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ public Collection<SAXParseException> validate(final Source xml) {
184184
}
185185
} catch (final SAXException ex) {
186186
throw new IllegalStateException(
187-
String.format("failed to create XSD schema from %s", this.xsd),
187+
String.format("Failed to create XSD schema from %s", this.xsd),
188188
ex
189189
);
190190
}
191191
final Collection<SAXParseException> errors =
192192
new CopyOnWriteArrayList<>();
193193
final Validator validator = schema.newValidator();
194-
validator.setErrorHandler(new ValidationHandler(errors));
194+
validator.setErrorHandler(new XSDDocument.ValidationHandler(errors));
195195
try {
196196
synchronized (XSDDocument.class) {
197197
validator.validate(xml);

src/main/java/com/jcabi/xml/XSLDocument.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public final class XSLDocument implements XSL {
8383
*
8484
* <p>This will NOT remove
8585
* existing indentation between Element nodes currently introduced by the
86-
* constructor of {@link com.jcabi.xml.XMLDocument}. For example:
86+
* constructor of {@link XMLDocument}. For example:
8787
*
8888
* <pre>
8989
* {@code
@@ -403,6 +403,7 @@ private void transformInto(final XML xml, final Result result) {
403403
final Transformer trans = this.transformer();
404404
final ConsoleErrorListener errors = new ConsoleErrorListener();
405405
trans.setErrorListener(errors);
406+
final long start = System.nanoTime();
406407
try {
407408
trans.transform(new DOMSource(xml.node()), result);
408409
} catch (final TransformerException ex) {
@@ -416,7 +417,12 @@ private void transformInto(final XML xml, final Result result) {
416417
);
417418
}
418419
if (Logger.isDebugEnabled(this)) {
419-
Logger.debug(this, "%s transformed XML", trans.getClass().getName());
420+
Logger.debug(
421+
this,
422+
"%s transformed XML in %[nano]s",
423+
trans.getClass().getName(),
424+
System.nanoTime() - start
425+
);
420426
}
421427
}
422428

@@ -464,12 +470,12 @@ private static Transformer forSaxon(final Transformer trans) {
464470
return trans;
465471
}
466472
if (Version.getStructuredVersionNumber()[0] < 11) {
467-
TransformerImpl.class.cast(trans)
473+
((TransformerImpl) trans)
468474
.getUnderlyingController()
469475
.setMessageEmitter(new MessageWarner());
470476
}
471477
if (Version.getStructuredVersionNumber()[0] >= 11) {
472-
TransformerImpl.class.cast(trans)
478+
((TransformerImpl) trans)
473479
.getUnderlyingController()
474480
.setMessageHandler(
475481
message -> Logger.error(

src/test/java/com/jcabi/xml/ClasspathInputTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
import org.w3c.dom.ls.LSInput;
3636

3737
/**
38-
* Test case for {@link com.jcabi.xml.ClasspathInput}.
38+
* Test case for {@link ClasspathInput}.
3939
* @since 0.17.3
4040
*/
41-
public final class ClasspathInputTest {
41+
final class ClasspathInputTest {
4242
@Test
43-
public void readsStringFromResourceSuccessfully() {
43+
void readsStringFromResourceSuccessfully() {
4444
final LSInput input = new ClasspathInput(
4545
"Id", "com/jcabi/xml/simple.xml"
4646
);

src/test/java/com/jcabi/xml/ClasspathSourcesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
* Test of ClasspathSources.
3838
* @since 0.18
3939
*/
40-
public final class ClasspathSourcesTest {
40+
final class ClasspathSourcesTest {
4141

4242
@Test
43-
public void sourcesResolvedFromBase() throws Exception {
43+
void sourcesResolvedFromBase() throws Exception {
4444
MatcherAssert.assertThat(
4545
new ClasspathSources().resolve("simple.xml", "com.jcabi.xml."),
4646
Matchers.notNullValue()

src/test/java/com/jcabi/xml/DomParserTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
* Test case for {@link DomParser}.
3939
* @since 0.1
4040
*/
41-
public final class DomParserTest {
41+
final class DomParserTest {
4242

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

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

6767
@Test
6868
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
69-
public void allowsValidXmlFormatting() {
70-
final String[] texts = new String[] {
69+
void allowsValidXmlFormatting() {
70+
final String[] texts = {
7171
"<?xml version=\"1.0\" encoding='ISO-8895-1'?><a/>",
7272
"<:a/>",
7373
"<ns:a><ns2:test-me/></ns:a>",

src/test/java/com/jcabi/xml/FileSourcesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
* Test of FileSources.
4242
* @since 0.18
4343
*/
44-
public final class FileSourcesTest {
44+
final class FileSourcesTest {
4545

4646
@Test
47-
public void sourcesResolvedFromDir() throws Exception {
47+
void sourcesResolvedFromDir() throws Exception {
4848
final File file = Files.createTempDirectory("")
4949
.resolve("dummy.xml").toFile();
5050
new LengthOf(new TeeInput("test", file)).value();

src/test/java/com/jcabi/xml/StrictXMLTest.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import org.junit.jupiter.api.Assumptions;
5151
import org.junit.jupiter.api.BeforeEach;
5252
import org.junit.jupiter.api.Test;
53+
import org.mockito.ArgumentMatchers;
5354
import org.mockito.Mockito;
5455
import org.mockito.stubbing.Answer;
5556

@@ -61,17 +62,17 @@
6162
* @checkstyle AbbreviationAsWordInNameCheck (5 lines)
6263
*/
6364
@SuppressWarnings({ "PMD.TooManyMethods", "PMD.AvoidDuplicateLiterals"})
64-
public final class StrictXMLTest {
65+
final class StrictXMLTest {
6566

6667
@BeforeEach
67-
public void weAreOnline() throws IOException {
68+
void weAreOnline() throws IOException {
6869
Assumptions.assumeTrue(
6970
InetAddress.getByName("w3.org").isReachable(1000)
7071
);
7172
}
7273

7374
@Test
74-
public void passesValidXmlThrough() {
75+
void passesValidXmlThrough() {
7576
new StrictXML(
7677
new XMLDocument("<root>passesValidXmlThrough</root>"),
7778
new XSDDocument(
@@ -85,7 +86,7 @@ public void passesValidXmlThrough() {
8586
}
8687

8788
@Test
88-
public void rejectsInvalidXmlThrough() {
89+
void rejectsInvalidXmlThrough() {
8990
Assertions.assertThrows(
9091
IllegalArgumentException.class,
9192
() -> new StrictXML(
@@ -101,7 +102,7 @@ public void rejectsInvalidXmlThrough() {
101102
}
102103

103104
@Test
104-
public void passesValidXmlUsingXsiSchemaLocation() throws Exception {
105+
void passesValidXmlUsingXsiSchemaLocation() throws Exception {
105106
new StrictXML(
106107
new XMLDocument(
107108
this.getClass().getResource("xsi-schemalocation-valid.xml")
@@ -110,7 +111,7 @@ public void passesValidXmlUsingXsiSchemaLocation() throws Exception {
110111
}
111112

112113
@Test
113-
public void rejectsInvalidXmlUsingXsiSchemaLocation() {
114+
void rejectsInvalidXmlUsingXsiSchemaLocation() {
114115
Assertions.assertThrows(
115116
IllegalStateException.class,
116117
() -> new StrictXML(
@@ -122,7 +123,7 @@ public void rejectsInvalidXmlUsingXsiSchemaLocation() {
122123
}
123124

124125
@Test
125-
public void validatesMultipleXmlsInThreads() throws Exception {
126+
void validatesMultipleXmlsInThreads() throws Exception {
126127
final int timeout = 10;
127128
final int numrun = 100;
128129
final int loop = 50;
@@ -176,7 +177,7 @@ public void validatesMultipleXmlsInThreads() throws Exception {
176177
}
177178

178179
@Test
179-
public void passesValidXmlWithNetworkProblems() throws Exception {
180+
void passesValidXmlWithNetworkProblems() throws Exception {
180181
final Validator validator = Mockito.mock(Validator.class);
181182
final AtomicInteger counter = new AtomicInteger(0);
182183
// @checkstyle IllegalThrowsCheck (5 lines)
@@ -190,7 +191,7 @@ public void passesValidXmlWithNetworkProblems() throws Exception {
190191
}
191192
return null;
192193
}
193-
).when(validator).validate(Mockito.any(Source.class));
194+
).when(validator).validate(ArgumentMatchers.any(Source.class));
194195
new StrictXML(
195196
new XMLDocument(
196197
"<root>passesValidXmlWithNetworkProblems</root>"
@@ -200,7 +201,7 @@ public void passesValidXmlWithNetworkProblems() throws Exception {
200201
}
201202

202203
@Test
203-
public void lookupXsdsFromClasspath() {
204+
void lookupXsdsFromClasspath() {
204205
new StrictXML(
205206
new XMLDocument(
206207
StringUtils.join(
@@ -224,7 +225,7 @@ public void lookupXsdsFromClasspath() {
224225
}
225226

226227
@Test
227-
public void rejectXmlWhenXsdIsNotAvailableOnClasspath() {
228+
void rejectXmlWhenXsdIsNotAvailableOnClasspath() {
228229
Assertions.assertThrows(
229230
IllegalArgumentException.class,
230231
() -> new StrictXML(
@@ -251,7 +252,7 @@ public void rejectXmlWhenXsdIsNotAvailableOnClasspath() {
251252
}
252253

253254
@Test
254-
public void handlesXmlWithoutSchemaLocation() {
255+
void handlesXmlWithoutSchemaLocation() {
255256
Assertions.assertThrows(
256257
IllegalArgumentException.class,
257258
() -> new StrictXML(

0 commit comments

Comments
 (0)