Skip to content

Commit

Permalink
#3636: cache folder
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 12, 2024
1 parent 30650b9 commit 7d6c669
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions eo-parser/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ SOFTWARE.
<artifactId>xax</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>mktmp</artifactId>
<!-- version from parent POM -->
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
16 changes: 13 additions & 3 deletions eo-parser/src/main/java/org/eolang/parser/StrictXmir.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ public final class StrictXmir implements XML {
* @param src The source
*/
public StrictXmir(final XML src) {
this.xml = new StrictXML(StrictXmir.reset(src));
this(src, Paths.get("target/xsd"));
}

/**
* Ctor.
* @param src The source
* @param tmp The directory with cached XSD files
*/
public StrictXmir(final XML src, final Path tmp) {
this.xml = new StrictXML(StrictXmir.reset(src, tmp));
}

@Override
Expand Down Expand Up @@ -125,9 +134,10 @@ public Collection<SAXParseException> validate(final XML schema) {
* Here, we check the location of the XSD in the XML
* and replace with a new one, if necessary.
* @param xml Original XML
* @param tmp Directory with cached XSD files
* @return New XML with the same node
*/
private static XML reset(final XML xml) {
private static XML reset(final XML xml, final Path tmp) {
final Node node = xml.inner();
final List<String> location = xml.xpath("/program/@xsi:noNamespaceSchemaLocation");
if (!location.isEmpty()) {
Expand All @@ -137,7 +147,7 @@ private static XML reset(final XML xml) {
"file:///%s",
StrictXmir.download(
uri,
Paths.get("target/xsd").resolve(
tmp.resolve(
uri.substring(uri.lastIndexOf('/') + 1)
)
).toString().replace("\\", "/")
Expand Down
15 changes: 13 additions & 2 deletions eo-parser/src/test/java/org/eolang/parser/StrictXmirTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
package org.eolang.parser;

import com.jcabi.xml.XMLDocument;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import java.nio.file.Path;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.xembly.Directives;
import org.xembly.Xembler;

Expand All @@ -38,7 +42,8 @@
final class StrictXmirTest {

@Test
void validatesXmir() throws Exception {
@ExtendWith(MktmpResolver.class)
void validatesXmir(@Mktmp final Path tmp) throws Exception {
MatcherAssert.assertThat(
"validation should pass as normal",
new StrictXmir(
Expand All @@ -55,10 +60,16 @@ void validatesXmir() throws Exception {
.add("objects")
).xml()
)
)
),
tmp
).validate(),
Matchers.emptyIterable()
);
MatcherAssert.assertThat(
"temporary XSD file created",
tmp.resolve("XMIR.xsd").toFile().exists(),
Matchers.is(true)
);
}

}

0 comments on commit 7d6c669

Please sign in to comment.