From 6cccc3721a261af04438ce97ec5525d807de7b0e Mon Sep 17 00:00:00 2001 From: mximp Date: Tue, 23 Aug 2022 16:09:14 +0300 Subject: [PATCH 01/39] #1062 Cache parsed mojo --- .../main/java/org/eolang/maven/Cached.java | 107 +++++++++++++++ .../main/java/org/eolang/maven/HashOfTag.java | 10 ++ .../main/java/org/eolang/maven/ParseMojo.java | 123 +++++++++++++----- .../main/java/org/eolang/maven/SafeMojo.java | 14 +- .../java/org/eolang/maven/CachedTest.java | 89 +++++++++++++ .../java/org/eolang/maven/ParseMojoTest.java | 46 +++++++ .../test/resources/org/eolang/maven/main.xmir | 30 +++++ 7 files changed, 387 insertions(+), 32 deletions(-) create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java create mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java create mode 100644 eo-maven-plugin/src/test/resources/org/eolang/maven/main.xmir diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java new file mode 100644 index 0000000000..ec81ea8440 --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java @@ -0,0 +1,107 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import java.io.IOException; +import java.nio.file.Path; +import org.cactoos.text.TextOf; + +/** + * Cached file in EO compilation process. The file is assumed to + * have text content in any format. + * @since 1.0 + */ +public class Cached { + /** + * Name of an object. + */ + private final String object; + + /** + * Version tag. + */ + private final String ver; + + /** + * Path to cache root. + */ + private final Path cache; + + /** + * Ctor. + * @param ver Version tag + * @param object Object name + * @param cache Cache root + */ + public Cached(final String ver, final String object, final Path cache) { + this.ver = ver; + this.object = object; + this.cache = cache; + } + + /** + * Get content of the cached object. + * @return Content + * @throws IOException In case of IO issue. + */ + @SuppressWarnings("PMD.AvoidCatchingGenericException") + public String content() throws IOException { + try { + return new TextOf( + this.path() + ).asString(); + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Exception ex) { + throw new IOException(ex); + } + } + + /** + * Is it cached? + * @return True if object exists in case and false otherwise + */ + public boolean exists() { + return this.path().toFile().exists(); + } + + /** + * Save content into the cache. + * @param content Content to cache + * @throws IOException In case of IO issues + */ + public void save(final String content) throws IOException { + new Save( + content, + this.path() + ).save(); + } + + /** + * Path to the object. + * @return Absolute path to the object file. + */ + private Path path() { + return this.cache.resolve(this.ver).resolve(this.object); + } +} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java index 9156eebb87..06001fcb37 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java @@ -34,6 +34,8 @@ /** * Hash of tag. * @since 0.26 + * @todo #1062:30min Make HashOfTag testable without accessing web. + * We need to be able to populate tags with custom values. */ final class HashOfTag { @@ -78,6 +80,14 @@ public String hash() { return result; } + /** + * Short version of hash. + * @return SHA of commit + */ + public String shortHash() { + return this.hash().substring(0, 7); + } + /** * Load all hashes and tags. * @return Map of them (hash -> tag) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index 7e20ff2ec1..b5c8fe45a3 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -66,6 +66,14 @@ public final class ParseMojo extends SafeMojo { */ public static final String DIR = "01-parse"; + /** + * Parsed cache directory. + * @checkstyle MemberNameCheck (7 lines) + */ + @Parameter(property = "eo.parsed.cache") + @SuppressWarnings("PMD.ImmutableField") + private Path cache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed"); + /** * Whether we should fail on error. * @checkstyle MemberNameCheck (7 lines) @@ -119,46 +127,99 @@ public void exec() throws IOException { private void parse(final Tojo tojo) throws IOException { final Path source = Paths.get(tojo.get(AssembleMojo.ATTR_EO)); final String name = tojo.get(Tojos.KEY); + final String ver = ParseMojo.verSafe(tojo); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - new Syntax( - name, - new InputOf(source), - new OutputTo(baos) - ).parse(); - // @checkstyle IllegalCatchCheck (1 line) - } catch (final RuntimeException ex) { - if (this.failOnError) { - throw new IllegalArgumentException( - String.format("Failed to parse %s", source), - ex - ); - } - Logger.warn( - this, "Parse was skipped due to failOnError=false. In file %s with error: %s", - source.toString(), - ex.getMessage() - ); - return; - } + final Cached cached = new Cached( + ParseMojo.safeHash(ver), + String.format("%s.%s", name, AssembleMojo.ATTR_XMIR), + this.cache + ); final Path target = new Place(name).make( - this.targetDir.toPath().resolve(ParseMojo.DIR), TranspileMojo.EXT + this.targetDir.toPath().resolve(ParseMojo.DIR), + TranspileMojo.EXT ); - new Save( - new XMLDocument( + if (ParseMojo.versioned(ver) && cached.exists()) { + Logger.info( + this, + "Found parsed in cache %s:%s", + Save.rel(source), + ver + ); + new Save( + cached.content(), + target + ).save(); + } else { + try { + new Syntax( + name, + new InputOf(source), + new OutputTo(baos) + ).parse(); + // @checkstyle IllegalCatchCheck (1 line) + } catch (final RuntimeException ex) { + if (this.failOnError) { + throw new IllegalArgumentException( + String.format("Failed to parse %s", source), + ex + ); + } + Logger.warn( + this, "Parse was skipped due to failOnError=false. In file %s with error: %s", + source.toString(), + ex.getMessage() + ); + return; + } + final String content = new XMLDocument( new Xembler( new Directives().xpath("/program").attr( "source", source.toAbsolutePath() ) ).applyQuietly(new XMLDocument(baos.toByteArray()).node()) - ).toString(), - target - ).save(); - Logger.debug( - this, "Parsed %s to %s", - Save.rel(source), Save.rel(target) - ); + ).toString(); + new Save(content, target).save(); + if (SafeMojo.versioned(ver)) { + cached.save(content); + } + Logger.debug( + this, "Parsed %s to %s", + Save.rel(source), Save.rel(target) + ); + } tojo.set(AssembleMojo.ATTR_XMIR, target.toAbsolutePath().toString()); } + /** + * Safely extract version attribute. + * @param tojo Source tojo + * @return Version value or empty string if attribute doesn't exist. + */ + private static String verSafe(final Tojo tojo) { + String ver = ""; + if (tojo.exists(AssembleMojo.ATTR_VERSION)) { + ver = tojo.get(AssembleMojo.ATTR_VERSION); + } + return ver; + } + + /** + * Get hash for the version. + * @param ver Version to tag + * @return Version tag + */ + private static String safeHash(final String ver) { + String hash; + try { + hash = new HashOfTag(ver).shortHash(); + } catch (final IllegalArgumentException ex) { + Logger.debug( + ParseMojo.class, + "Unable to get hash for ver %s", + ver + ); + hash = "0000000"; + } + return hash; + } } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java index d545260425..753e731493 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java @@ -169,10 +169,22 @@ public List select(final Predicate filter) { }; } + /** + * Is it a true version? + * @param ver Version to check + * @return True if version has meaningful value and false otherwise + */ + @SuppressWarnings("PMD.ProhibitPublicStaticMethods") + protected static boolean versioned(final String ver) { + final String trimmed = ver.trim(); + return !trimmed.isEmpty() + && !trimmed.equals("0.0.0") + && !trimmed.equals("*.*.*"); + } + /** * Exec it. * @throws IOException If fails */ abstract void exec() throws IOException; - } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java new file mode 100644 index 0000000000..b924b07454 --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java @@ -0,0 +1,89 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import java.nio.file.Path; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests for Cached. + * @since 1.0 + */ +public final class CachedTest { + @Test + public void testContentOfCachedFile(@TempDir final Path temp) throws Exception { + final String content = String.join( + "\n", + "", + "", + "" + ); + new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")) + .save(content); + MatcherAssert.assertThat( + new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")).content(), + Matchers.equalTo(content) + ); + } + + @Test + public void testCachedObjectExists(@TempDir final Path temp) throws Exception { + new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")) + .save( + String.join( + "\n", + "", + "", + "" + ) + ); + MatcherAssert.assertThat( + new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")).exists(), + Matchers.is(true) + ); + } + + @ValueSource(strings = {"1.0.0", "0.0.1", "abc", "a.b.c.0"}) + @ParameterizedTest + public void testMeaningfulVersion(final String ver) { + MatcherAssert.assertThat( + ParseMojo.versioned(ver), + Matchers.is(true) + ); + } + + @ValueSource(strings = {"0.0.0", "*.*.*", "", " "}) + @ParameterizedTest + public void testNoVersion(final String ver) { + MatcherAssert.assertThat( + ParseMojo.versioned(ver), + Matchers.is(false) + ); + } +} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index f09072692b..71b6af98e3 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -28,6 +28,8 @@ import com.yegor256.tojos.SmartTojos; import java.nio.file.Files; import java.nio.file.Path; +import org.cactoos.io.ResourceOf; +import org.cactoos.text.TextOf; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; @@ -39,6 +41,7 @@ * * @since 0.1 */ +@SuppressWarnings("PMD.AvoidDuplicateLiterals") public final class ParseMojoTest { @Test @@ -75,6 +78,49 @@ public void testSimpleParsing(@TempDir final Path temp) throws Exception { ); } + @Test + public void testSimpleParsingCached(@TempDir final Path temp) throws Exception { + final Path src = temp.resolve("foo/x/main.eo"); + final Path target = temp.resolve("target"); + new Save( + "invalid content", + src + ).save(); + final Path foreign = temp.resolve("eo-foreign.json"); + new Cached( + new HashOfTag("0.25.0").shortHash(), + "foo.x.main.xmir", + temp.resolve("parsed") + ).save( + new TextOf(new ResourceOf("org/eolang/maven/main.xmir")).asString() + ); + new MonoTojos(new Csv(foreign)) + .add("foo.x.main") + .set(AssembleMojo.ATTR_SCOPE, "compile") + .set(AssembleMojo.ATTR_EO, src.toString()) + .set(AssembleMojo.ATTR_VERSION, "0.25.0"); + new Moja<>(ParseMojo.class) + .with("targetDir", target.toFile()) + .with("foreign", foreign.toFile()) + .with("foreignFormat", "csv") + .with("cache", temp.resolve("parsed")) + .execute(); + MatcherAssert.assertThat( + Files.exists( + target.resolve( + String.format("%s/foo/x/main.%s", ParseMojo.DIR, TranspileMojo.EXT) + ) + ), + Matchers.is(true) + ); + MatcherAssert.assertThat( + new SmartTojos( + new MonoTojos(new Csv(foreign)) + ).getById("foo.x.main").exists("xmir"), + Matchers.is(true) + ); + } + @Test public void testCrashOnInvalidSyntax(@TempDir final Path temp) throws Exception { diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/main.xmir b/eo-maven-plugin/src/test/resources/org/eolang/maven/main.xmir new file mode 100644 index 0000000000..c8fa8d90d9 --- /dev/null +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/main.xmir @@ -0,0 +1,30 @@ + + + +package f + +[args] > main + (stdout "Hello!").print + + + + + + package + f + f + + + + + + + Hello! + + + + + \ No newline at end of file From 76247a19b099237c893a7bc1840941fe24f50593 Mon Sep 17 00:00:00 2001 From: mximp Date: Tue, 23 Aug 2022 16:28:01 +0300 Subject: [PATCH 02/39] #1062 fix checkstyle --- .../src/test/java/org/eolang/maven/CachedTest.java | 10 +++++----- .../src/test/java/org/eolang/maven/ParseMojoTest.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java index b924b07454..3876b48d72 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java @@ -35,9 +35,9 @@ * Tests for Cached. * @since 1.0 */ -public final class CachedTest { +final class CachedTest { @Test - public void testContentOfCachedFile(@TempDir final Path temp) throws Exception { + void testContentOfCachedFile(@TempDir final Path temp) throws Exception { final String content = String.join( "\n", "", @@ -53,7 +53,7 @@ public void testContentOfCachedFile(@TempDir final Path temp) throws Exception { } @Test - public void testCachedObjectExists(@TempDir final Path temp) throws Exception { + void testCachedObjectExists(@TempDir final Path temp) throws Exception { new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")) .save( String.join( @@ -71,7 +71,7 @@ public void testCachedObjectExists(@TempDir final Path temp) throws Exception { @ValueSource(strings = {"1.0.0", "0.0.1", "abc", "a.b.c.0"}) @ParameterizedTest - public void testMeaningfulVersion(final String ver) { + void testMeaningfulVersion(final String ver) { MatcherAssert.assertThat( ParseMojo.versioned(ver), Matchers.is(true) @@ -80,7 +80,7 @@ public void testMeaningfulVersion(final String ver) { @ValueSource(strings = {"0.0.0", "*.*.*", "", " "}) @ParameterizedTest - public void testNoVersion(final String ver) { + void testNoVersion(final String ver) { MatcherAssert.assertThat( ParseMojo.versioned(ver), Matchers.is(false) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index 9258148cd7..b2d8a8771a 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -42,7 +42,7 @@ * @since 0.1 */ @SuppressWarnings("PMD.AvoidDuplicateLiterals") -public final class ParseMojoTest { +final class ParseMojoTest { @Test void testSimpleParsing(@TempDir final Path temp) throws Exception { From bd86930979de5ee0fa4faa71a3cf26f17952575b Mon Sep 17 00:00:00 2001 From: mximp Date: Tue, 23 Aug 2022 19:01:47 +0300 Subject: [PATCH 03/39] #1062 fix versioning + docs --- eo-maven-plugin/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eo-maven-plugin/README.md b/eo-maven-plugin/README.md index 7e67d07f86..4641276d63 100644 --- a/eo-maven-plugin/README.md +++ b/eo-maven-plugin/README.md @@ -86,6 +86,8 @@ one after another: the source code in a plain text format and parses into XML document, using [ANTLR4](https://www.antlr.org/) and [Xembly](https://www.xembly.org). The output of the parser you can find in the `target/eo/parse` directory. + Parsed objects which are versioned (normally pulled from + [Objectionary](https://github.com/objectionary/home)) are cached in `.eo/parsed` folder. * **Optimization**. There are a number of [XSL transformations](https://en.wikipedia.org/wiki/XSLT) From 84d742179c16a28e9532b3e7b00e3be256a708a3 Mon Sep 17 00:00:00 2001 From: mximp Date: Tue, 23 Aug 2022 19:06:29 +0300 Subject: [PATCH 04/39] #1062 fix versioning + docs --- eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index b5c8fe45a3..77dc64b890 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -196,7 +196,7 @@ private void parse(final Tojo tojo) throws IOException { * @return Version value or empty string if attribute doesn't exist. */ private static String verSafe(final Tojo tojo) { - String ver = ""; + String ver = ParseMojo.ZERO; if (tojo.exists(AssembleMojo.ATTR_VERSION)) { ver = tojo.get(AssembleMojo.ATTR_VERSION); } @@ -218,7 +218,7 @@ private static String safeHash(final String ver) { "Unable to get hash for ver %s", ver ); - hash = "0000000"; + hash = ver; } return hash; } From c24fa0fd3a964ad1f948bed6c552a5ef71f00bed Mon Sep 17 00:00:00 2001 From: mximp Date: Tue, 23 Aug 2022 19:11:51 +0300 Subject: [PATCH 05/39] #1062 puzzle fix --- eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java index 06001fcb37..247f6ee1e2 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java @@ -35,7 +35,8 @@ * Hash of tag. * @since 0.26 * @todo #1062:30min Make HashOfTag testable without accessing web. - * We need to be able to populate tags with custom values. + * We need to be able to populate tags with custom values rather than + * always download it from the web. */ final class HashOfTag { From a9878955c0debe1044a387bea21dfbe9997ec821 Mon Sep 17 00:00:00 2001 From: mximp Date: Wed, 24 Aug 2022 12:45:42 +0300 Subject: [PATCH 06/39] #1062 review fixes --- .../src/main/java/org/eolang/maven/Cached.java | 12 ++++-------- .../src/main/java/org/eolang/maven/ParseMojo.java | 3 +++ .../src/main/java/org/eolang/maven/PullMojo.java | 9 ++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java index ec81ea8440..de3f7ada81 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.nio.file.Path; +import org.cactoos.text.IoCheckedText; import org.cactoos.text.TextOf; /** @@ -67,14 +68,9 @@ public Cached(final String ver, final String object, final Path cache) { */ @SuppressWarnings("PMD.AvoidCatchingGenericException") public String content() throws IOException { - try { - return new TextOf( - this.path() - ).asString(); - // @checkstyle IllegalCatchCheck (1 line) - } catch (final Exception ex) { - throw new IOException(ex); - } + return new IoCheckedText( + new TextOf(this.path()) + ).asString(); } /** diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index 77dc64b890..d14b9c581e 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -207,6 +207,9 @@ private static String verSafe(final Tojo tojo) { * Get hash for the version. * @param ver Version to tag * @return Version tag + * @todo #1062:30mins Lets introduce new method `HashOfTag.contains()` + * and get rid of exception-driven workflow. We can use new method + * to check the existence of tag to be hashed and behave accordingly. */ private static String safeHash(final String ver) { String hash; diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java index f983b34a76..fedf9fabea 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java @@ -89,17 +89,16 @@ public void exec() throws IOException { && !row.exists(AssembleMojo.ATTR_XMIR) ); if (this.objectionary == null) { - final String full = new HashOfTag(this.hash).hash(); - final String small = full.substring(0, 7); + final HashOfTag tag = new HashOfTag(this.hash); this.objectionary = new OyFallbackSwap( new OyHome( - small, + tag.shortHash(), this.outputPath ), new OyCaching( - small, + tag.shortHash(), this.outputPath, - PullMojo.remote(full) + PullMojo.remote(tag.hash()) ), this.forceUpdate() ); From 8672ec8fc581a98a551b2b13c95bea51c833a852 Mon Sep 17 00:00:00 2001 From: mximp Date: Wed, 24 Aug 2022 20:17:40 +0300 Subject: [PATCH 07/39] #1062 review fixes --- eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java | 2 +- eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java | 2 +- eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java | 2 +- eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java | 4 ++-- .../src/test/java/org/eolang/maven/ParseMojoTest.java | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java index de3f7ada81..9b55fdf1e7 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java @@ -75,7 +75,7 @@ public String content() throws IOException { /** * Is it cached? - * @return True if object exists in case and false otherwise + * @return True if object exists in cache and false otherwise */ public boolean exists() { return this.path().toFile().exists(); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java index 247f6ee1e2..a94d63a444 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java @@ -85,7 +85,7 @@ public String hash() { * Short version of hash. * @return SHA of commit */ - public String shortHash() { + public String narrow() { return this.hash().substring(0, 7); } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index d14b9c581e..5929173702 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -214,7 +214,7 @@ private static String verSafe(final Tojo tojo) { private static String safeHash(final String ver) { String hash; try { - hash = new HashOfTag(ver).shortHash(); + hash = new HashOfTag(ver).narrow(); } catch (final IllegalArgumentException ex) { Logger.debug( ParseMojo.class, diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java index fedf9fabea..af055bad66 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java @@ -92,11 +92,11 @@ public void exec() throws IOException { final HashOfTag tag = new HashOfTag(this.hash); this.objectionary = new OyFallbackSwap( new OyHome( - tag.shortHash(), + tag.narrow(), this.outputPath ), new OyCaching( - tag.shortHash(), + tag.narrow(), this.outputPath, PullMojo.remote(tag.hash()) ), diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index b2d8a8771a..61d5dc7907 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -88,7 +88,7 @@ void testSimpleParsingCached(@TempDir final Path temp) throws Exception { ).save(); final Path foreign = temp.resolve("eo-foreign.json"); new Cached( - new HashOfTag("0.25.0").shortHash(), + new HashOfTag("0.25.0").narrow(), "foo.x.main.xmir", temp.resolve("parsed") ).save( From 73c1206e1639e882df89d659f777ab4f38d1859b Mon Sep 17 00:00:00 2001 From: mximp Date: Thu, 25 Aug 2022 13:33:43 +0300 Subject: [PATCH 08/39] #1062 `Cached` refactoring for better readability --- .../src/main/java/org/eolang/maven/Cached.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java index 9b55fdf1e7..8d3d4c575f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java @@ -29,15 +29,16 @@ import org.cactoos.text.TextOf; /** - * Cached file in EO compilation process. The file is assumed to - * have text content in any format. + * Cached object in EO compilation process. + * The object is assumed to have text content in any format. + * The object is identified by {@link #name} and {@link #ver} combination. * @since 1.0 */ public class Cached { /** * Name of an object. */ - private final String object; + private final String name; /** * Version tag. @@ -52,12 +53,12 @@ public class Cached { /** * Ctor. * @param ver Version tag - * @param object Object name + * @param name Object name * @param cache Cache root */ - public Cached(final String ver, final String object, final Path cache) { + public Cached(final String ver, final String name, final Path cache) { this.ver = ver; - this.object = object; + this.name = name; this.cache = cache; } @@ -98,6 +99,6 @@ public void save(final String content) throws IOException { * @return Absolute path to the object file. */ private Path path() { - return this.cache.resolve(this.ver).resolve(this.object); + return this.cache.resolve(this.ver).resolve(this.name); } } From 70b9f71b89e55be5489c03cf49fa80fbca2be651 Mon Sep 17 00:00:00 2001 From: mximp Date: Mon, 29 Aug 2022 18:37:56 +0300 Subject: [PATCH 09/39] #1062 Replace Cached with Footprint --- .../main/java/org/eolang/maven/Cached.java | 104 ------------ .../main/java/org/eolang/maven/Footprint.java | 149 ++++++++++++++++++ .../main/java/org/eolang/maven/ParseMojo.java | 100 ++++++------ .../main/java/org/eolang/maven/SafeMojo.java | 13 -- .../{CachedTest.java => FootprintTest.java} | 50 ++---- .../java/org/eolang/maven/ParseMojoTest.java | 11 +- 6 files changed, 220 insertions(+), 207 deletions(-) delete mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java rename eo-maven-plugin/src/test/java/org/eolang/maven/{CachedTest.java => FootprintTest.java} (63%) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java deleted file mode 100644 index 8d3d4c575f..0000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Cached.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2022 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package org.eolang.maven; - -import java.io.IOException; -import java.nio.file.Path; -import org.cactoos.text.IoCheckedText; -import org.cactoos.text.TextOf; - -/** - * Cached object in EO compilation process. - * The object is assumed to have text content in any format. - * The object is identified by {@link #name} and {@link #ver} combination. - * @since 1.0 - */ -public class Cached { - /** - * Name of an object. - */ - private final String name; - - /** - * Version tag. - */ - private final String ver; - - /** - * Path to cache root. - */ - private final Path cache; - - /** - * Ctor. - * @param ver Version tag - * @param name Object name - * @param cache Cache root - */ - public Cached(final String ver, final String name, final Path cache) { - this.ver = ver; - this.name = name; - this.cache = cache; - } - - /** - * Get content of the cached object. - * @return Content - * @throws IOException In case of IO issue. - */ - @SuppressWarnings("PMD.AvoidCatchingGenericException") - public String content() throws IOException { - return new IoCheckedText( - new TextOf(this.path()) - ).asString(); - } - - /** - * Is it cached? - * @return True if object exists in cache and false otherwise - */ - public boolean exists() { - return this.path().toFile().exists(); - } - - /** - * Save content into the cache. - * @param content Content to cache - * @throws IOException In case of IO issues - */ - public void save(final String content) throws IOException { - new Save( - content, - this.path() - ).save(); - } - - /** - * Path to the object. - * @return Absolute path to the object file. - */ - private Path path() { - return this.cache.resolve(this.ver).resolve(this.name); - } -} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java new file mode 100644 index 0000000000..38f31b4fe1 --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -0,0 +1,149 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import com.jcabi.log.Logger; +import java.io.IOException; +import java.nio.file.Path; +import java.util.function.Supplier; +import org.cactoos.text.IoCheckedText; +import org.cactoos.text.TextOf; + +/** + * Program footprint in EO compilation process. + * The footprint consists of file in the {@link #main} folder and optionally cached + * file in {@link #cache} folder. + * Caching is applied if {@link #ver} represents true version in terms of + * {@link #versioned(String)} method. + *
Usage example: + * + *
+ *    final Footprint footprint = new Footprint(
+ *      version,
+ *      targetRoot,
+ *      cacheRoot
+ *    ).save(program, ext);
+ *  
+ *
+ * @since 1.0 + */ +public class Footprint { + /** + * Path to target root. + */ + private final Path main; + + /** + * Version tag. + */ + private final String ver; + + /** + * Path to cache root. + */ + private final Path cache; + + /** + * Ctor. + * @param ver Version tag + * @param main Main root + * @param cache Cache root + */ + public Footprint(final String ver, final Path main, final Path cache) { + this.ver = ver; + this.main = main; + this.cache = cache; + } + + /** + * Get content of the program. + * @param program Program name + * @param ext File extension + * @return Content of a file + * @throws IOException In case of IO issue. + */ + @SuppressWarnings("PMD.AvoidCatchingGenericException") + public String content(final String program, final String ext) throws IOException { + final Path cached = new Place(program).make(this.cache.resolve(this.ver), ext); + final Path target = new Place(program).make(this.main, ext); + final IoCheckedText content; + if (Footprint.versioned(this.ver) && cached.toFile().exists()) { + content = new IoCheckedText( + new TextOf(cached) + ); + } else { + content = new IoCheckedText( + new TextOf(target) + ); + } + return content.asString(); + } + + /** + * Save content. + * @param program Program name + * @param ext File extension + * @param content File content + * @throws IOException In case of IO issues + */ + public void save(final String program, final String ext, final Supplier content) + throws IOException { + final Path cached = new Place(program).make(this.cache.resolve(this.ver), ext); + final Path target = new Place(program).make(this.main, ext); + final String text; + if (Footprint.versioned(this.ver) && cached.toFile().exists()) { + Logger.info( + this, + "File found in cache: %s", + cached + ); + text = this.content(program, ext); + } else { + text = content.get(); + if (Footprint.versioned(this.ver)) { + new Save( + text, + cached + ).save(); + } + } + new Save( + text, + target + ).save(); + } + + /** + * Is it a true version? + * @param ver Version to check + * @return True if version has meaningful value and false otherwise + */ + @SuppressWarnings("PMD.ProhibitPublicStaticMethods") + private static boolean versioned(final String ver) { + final String trimmed = ver.trim(); + return !trimmed.isEmpty() + && !trimmed.equals("0.0.0") + && !trimmed.equals("*.*.*"); + } +} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index 5929173702..ab5c945830 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -123,71 +123,63 @@ public void exec() throws IOException { * @param tojo The tojo * @throws IOException If fails */ - @SuppressWarnings("PMD.AvoidCatchingGenericException") + @SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.ExceptionAsFlowControl"}) private void parse(final Tojo tojo) throws IOException { final Path source = Paths.get(tojo.get(AssembleMojo.ATTR_EO)); final String name = tojo.get(Tojos.KEY); - final String ver = ParseMojo.verSafe(tojo); - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final Cached cached = new Cached( - ParseMojo.safeHash(ver), - String.format("%s.%s", name, AssembleMojo.ATTR_XMIR), - this.cache - ); - final Path target = new Place(name).make( + final Footprint footprint = new Footprint( + ParseMojo.safeHash(ParseMojo.verSafe(tojo)), this.targetDir.toPath().resolve(ParseMojo.DIR), - TranspileMojo.EXT + this.cache ); - if (ParseMojo.versioned(ver) && cached.exists()) { - Logger.info( - this, - "Found parsed in cache %s:%s", - Save.rel(source), - ver - ); - new Save( - cached.content(), - target - ).save(); - } else { - try { - new Syntax( - name, - new InputOf(source), - new OutputTo(baos) - ).parse(); - // @checkstyle IllegalCatchCheck (1 line) - } catch (final RuntimeException ex) { - if (this.failOnError) { - throw new IllegalArgumentException( - String.format("Failed to parse %s", source), - ex - ); + try { + footprint.save( + name, + AssembleMojo.ATTR_XMIR, + () -> { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + new Syntax( + name, + new InputOf(source), + new OutputTo(baos) + ).parse(); + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Exception ex) { + throw new IllegalArgumentException( + String.format("Failed to parse %s", source), + ex + ); + } + return new XMLDocument( + new Xembler( + new Directives().xpath("/program").attr( + "source", + source.toAbsolutePath() + ) + ).applyQuietly(new XMLDocument(baos.toByteArray()).node()) + ).toString(); } - Logger.warn( - this, "Parse was skipped due to failOnError=false. In file %s with error: %s", - source.toString(), - ex.getMessage() - ); - return; - } - final String content = new XMLDocument( - new Xembler( - new Directives().xpath("/program").attr( - "source", source.toAbsolutePath() - ) - ).applyQuietly(new XMLDocument(baos.toByteArray()).node()) - ).toString(); - new Save(content, target).save(); - if (SafeMojo.versioned(ver)) { - cached.save(content); - } + ); + final Path target = new Place(name).make( + this.targetDir.toPath().resolve(ParseMojo.DIR), + TranspileMojo.EXT + ); + tojo.set(AssembleMojo.ATTR_XMIR, target.toAbsolutePath().toString()); Logger.debug( this, "Parsed %s to %s", Save.rel(source), Save.rel(target) ); + } catch (final IllegalArgumentException ex) { + if (this.failOnError || !ex.getMessage().contains("Failed to parse")) { + throw ex; + } + Logger.warn( + this, "Parse was skipped due to failOnError=false. In file %s with error: %s", + source.toString(), + ex.getMessage() + ); } - tojo.set(AssembleMojo.ATTR_XMIR, target.toAbsolutePath().toString()); } /** diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java index 3a138d9b54..c6add4805e 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java @@ -217,19 +217,6 @@ public List select(final Predicate filter) { }; } - /** - * Is it a true version? - * @param ver Version to check - * @return True if version has meaningful value and false otherwise - */ - @SuppressWarnings("PMD.ProhibitPublicStaticMethods") - protected static boolean versioned(final String ver) { - final String trimmed = ver.trim(); - return !trimmed.isEmpty() - && !trimmed.equals("0.0.0") - && !trimmed.equals("*.*.*"); - } - /** * Exec it. * @throws IOException If fails diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java similarity index 63% rename from eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java rename to eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java index 3876b48d72..10ec1087c8 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/CachedTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java @@ -35,7 +35,7 @@ * Tests for Cached. * @since 1.0 */ -final class CachedTest { +final class FootprintTest { @Test void testContentOfCachedFile(@TempDir final Path temp) throws Exception { final String content = String.join( @@ -44,46 +44,30 @@ void testContentOfCachedFile(@TempDir final Path temp) throws Exception { "", "" ); - new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")) - .save(content); + new Footprint("1.0.0", temp.resolve("target"), temp.resolve("parsed")) + .save("org.eolang.txt.text", "xmir", () -> content); MatcherAssert.assertThat( - new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")).content(), + new Footprint("1.0.0", temp.resolve("target"), temp.resolve("parsed")) + .content("org.eolang.txt.text", "xmir"), Matchers.equalTo(content) ); } - @Test - void testCachedObjectExists(@TempDir final Path temp) throws Exception { - new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")) - .save( - String.join( - "\n", - "", - "", - "" - ) - ); - MatcherAssert.assertThat( - new Cached("1.0.0", "org.eolang.txt.text.xmir", temp.resolve("parsed")).exists(), - Matchers.is(true) - ); - } - - @ValueSource(strings = {"1.0.0", "0.0.1", "abc", "a.b.c.0"}) - @ParameterizedTest - void testMeaningfulVersion(final String ver) { - MatcherAssert.assertThat( - ParseMojo.versioned(ver), - Matchers.is(true) - ); - } - @ValueSource(strings = {"0.0.0", "*.*.*", "", " "}) @ParameterizedTest - void testNoVersion(final String ver) { + void testContentOfNoCacheFile(final String ver, @TempDir final Path temp) throws Exception { + final String content = String.join( + "\n", + "", + "", + "" + ); + new Footprint(ver, temp.resolve("target"), temp.resolve("parsed")) + .save("org.eolang.txt.text", "xmir", () -> content); MatcherAssert.assertThat( - ParseMojo.versioned(ver), - Matchers.is(false) + new Footprint("*.*.*", temp.resolve("target"), temp.resolve("parsed")) + .content("org.eolang.txt.text", "xmir"), + Matchers.equalTo(content) ); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index 61d5dc7907..08ea9546cc 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -30,6 +30,7 @@ import java.nio.file.Path; import org.cactoos.io.ResourceOf; import org.cactoos.text.TextOf; +import org.cactoos.text.UncheckedText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; @@ -87,12 +88,16 @@ void testSimpleParsingCached(@TempDir final Path temp) throws Exception { src ).save(); final Path foreign = temp.resolve("eo-foreign.json"); - new Cached( + new Footprint( new HashOfTag("0.25.0").narrow(), - "foo.x.main.xmir", + target, temp.resolve("parsed") ).save( - new TextOf(new ResourceOf("org/eolang/maven/main.xmir")).asString() + "foo.x.main", + "xmir", + () -> new UncheckedText( + new TextOf(new ResourceOf("org/eolang/maven/main.xmir")) + ).asString() ); new MonoTojos(new Csv(foreign)) .add("foo.x.main") From dd34f8427acdaff68b0c46f431ced72d9b5fb685 Mon Sep 17 00:00:00 2001 From: mximp Date: Mon, 29 Aug 2022 19:04:02 +0300 Subject: [PATCH 10/39] #1062 Safe ver --- .../src/main/java/org/eolang/maven/Footprint.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java index 38f31b4fe1..672bcfb095 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -85,7 +85,7 @@ public Footprint(final String ver, final Path main, final Path cache) { */ @SuppressWarnings("PMD.AvoidCatchingGenericException") public String content(final String program, final String ext) throws IOException { - final Path cached = new Place(program).make(this.cache.resolve(this.ver), ext); + final Path cached = new Place(program).make(this.cache.resolve(this.safeVer()), ext); final Path target = new Place(program).make(this.main, ext); final IoCheckedText content; if (Footprint.versioned(this.ver) && cached.toFile().exists()) { @@ -109,7 +109,7 @@ public String content(final String program, final String ext) throws IOException */ public void save(final String program, final String ext, final Supplier content) throws IOException { - final Path cached = new Place(program).make(this.cache.resolve(this.ver), ext); + final Path cached = new Place(program).make(this.cache.resolve(this.safeVer()), ext); final Path target = new Place(program).make(this.main, ext); final String text; if (Footprint.versioned(this.ver) && cached.toFile().exists()) { @@ -134,6 +134,14 @@ public void save(final String program, final String ext, final Supplier ).save(); } + /** + * Transform version for legal path. + * @return Version tag + */ + private String safeVer() { + return this.ver.replaceAll("\\*", "_"); + } + /** * Is it a true version? * @param ver Version to check From 85dc2a99df3a9aa3e3a3d6015a93c34f86e27ecf Mon Sep 17 00:00:00 2001 From: mximp Date: Mon, 29 Aug 2022 19:18:26 +0300 Subject: [PATCH 11/39] #1062 Safe ver --- eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java index 672bcfb095..7a99bcc01f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -139,7 +139,8 @@ public void save(final String program, final String ext, final Supplier * @return Version tag */ private String safeVer() { - return this.ver.replaceAll("\\*", "_"); + return this.ver + .replaceAll("[* ]", "_"); } /** From df40f1dad4f849485cd13980d09d343ee2c3bbb4 Mon Sep 17 00:00:00 2001 From: mximp Date: Tue, 30 Aug 2022 10:12:03 +0300 Subject: [PATCH 12/39] #1062 Review corrections --- .../main/java/org/eolang/maven/Footprint.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java index 7a99bcc01f..7d087b79fa 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -31,12 +31,12 @@ import org.cactoos.text.TextOf; /** - * Program footprint in EO compilation process. - * The footprint consists of file in the {@link #main} folder and optionally cached + * Program footprint of EO compilation process. + *

The footprint consists of file in {@link #main} folder and optionally cached * file in {@link #cache} folder. * Caching is applied if {@link #ver} represents true version in terms of * {@link #versioned(String)} method. - *
Usage example: + *

Usage example: * *

  *    final Footprint footprint = new Footprint(
@@ -44,6 +44,8 @@
  *      targetRoot,
  *      cacheRoot
  *    ).save(program, ext);
+ *
+ *    String content = footprint.content(program, ext);
  *  
* * @since 1.0 @@ -77,9 +79,9 @@ public Footprint(final String ver, final Path main, final Path cache) { } /** - * Get content of the program. + * Get program content of a specific type. * @param program Program name - * @param ext File extension + * @param ext File extension which defines the type * @return Content of a file * @throws IOException In case of IO issue. */ @@ -139,8 +141,7 @@ public void save(final String program, final String ext, final Supplier * @return Version tag */ private String safeVer() { - return this.ver - .replaceAll("[* ]", "_"); + return this.ver.replaceAll("[* ]", "_"); } /** @@ -148,7 +149,6 @@ private String safeVer() { * @param ver Version to check * @return True if version has meaningful value and false otherwise */ - @SuppressWarnings("PMD.ProhibitPublicStaticMethods") private static boolean versioned(final String ver) { final String trimmed = ver.trim(); return !trimmed.isEmpty() From 305d49a8c7ed92ebc54674ec8993877c28103c67 Mon Sep 17 00:00:00 2001 From: OlesiaSub Date: Thu, 1 Sep 2022 11:16:42 +0300 Subject: [PATCH 13/39] Remove data puzzle --- .../src/main/resources/org/eolang/maven/pre/data.xsl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/data.xsl b/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/data.xsl index b523f84e27..61be3018f1 100644 --- a/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/data.xsl +++ b/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/data.xsl @@ -22,12 +22,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - From 02419396670d975a1d1af0d4bafc3655d25429ed Mon Sep 17 00:00:00 2001 From: mximp Date: Fri, 2 Sep 2022 09:55:56 +0300 Subject: [PATCH 14/39] #1062 Exception handling refactoring --- .../main/java/org/eolang/maven/Footprint.java | 7 +- .../main/java/org/eolang/maven/MarkMojo.java | 4 + .../main/java/org/eolang/maven/ParseMojo.java | 97 ++++++------------- .../java/org/eolang/maven/ParseMojoTest.java | 2 +- 4 files changed, 41 insertions(+), 69 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java index 7d087b79fa..afea64c8a1 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -26,7 +26,8 @@ import com.jcabi.log.Logger; import java.io.IOException; import java.nio.file.Path; -import java.util.function.Supplier; +import org.cactoos.Scalar; +import org.cactoos.scalar.IoChecked; import org.cactoos.text.IoCheckedText; import org.cactoos.text.TextOf; @@ -109,7 +110,7 @@ public String content(final String program, final String ext) throws IOException * @param content File content * @throws IOException In case of IO issues */ - public void save(final String program, final String ext, final Supplier content) + public void save(final String program, final String ext, final Scalar content) throws IOException { final Path cached = new Place(program).make(this.cache.resolve(this.safeVer()), ext); final Path target = new Place(program).make(this.main, ext); @@ -122,7 +123,7 @@ public void save(final String program, final String ext, final Supplier ); text = this.content(program, ext); } else { - text = content.get(); + text = new IoChecked<>(content).value(); if (Footprint.versioned(this.ver)) { new Save( text, diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/MarkMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/MarkMojo.java index 76e32a7fad..5091930c32 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/MarkMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/MarkMojo.java @@ -77,6 +77,10 @@ public void exec() throws IOException { * @param version The version of the JAR * @return How many registered * @throws IOException If fails + * @todo #1062:30min The mojo doesn't update program version if it exists. + * This causes versions like `*.*.*` and `0.0.0` are not updated and remain + * in foreign catalog. This needs to be updated: version must be overridden to + * correct value. */ private int scan(final Path dir, final String version) throws IOException { final Unplace unplace = new Unplace(dir); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index ab5c945830..d1da5cb38f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -38,6 +38,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.cactoos.io.InputOf; import org.cactoos.io.OutputTo; +import org.eolang.parser.ParsingException; import org.eolang.parser.Syntax; import org.xembly.Directives; import org.xembly.Xembler; @@ -75,7 +76,7 @@ public final class ParseMojo extends SafeMojo { private Path cache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed"); /** - * Whether we should fail on error. + * Whether we should fail on parsing error. * @checkstyle MemberNameCheck (7 lines) * @since 0.23.0 */ @@ -127,8 +128,14 @@ public void exec() throws IOException { private void parse(final Tojo tojo) throws IOException { final Path source = Paths.get(tojo.get(AssembleMojo.ATTR_EO)); final String name = tojo.get(Tojos.KEY); + final String version; + if (tojo.exists(AssembleMojo.ATTR_VERSION)) { + version = tojo.get(AssembleMojo.ATTR_VERSION); + } else { + version = ParseMojo.ZERO; + } final Footprint footprint = new Footprint( - ParseMojo.safeHash(ParseMojo.verSafe(tojo)), + version, this.targetDir.toPath().resolve(ParseMojo.DIR), this.cache ); @@ -138,19 +145,11 @@ private void parse(final Tojo tojo) throws IOException { AssembleMojo.ATTR_XMIR, () -> { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - new Syntax( - name, - new InputOf(source), - new OutputTo(baos) - ).parse(); - // @checkstyle IllegalCatchCheck (1 line) - } catch (final Exception ex) { - throw new IllegalArgumentException( - String.format("Failed to parse %s", source), - ex - ); - } + new Syntax( + name, + new InputOf(source), + new OutputTo(baos) + ).parse(); return new XMLDocument( new Xembler( new Directives().xpath("/program").attr( @@ -161,60 +160,28 @@ private void parse(final Tojo tojo) throws IOException { ).toString(); } ); - final Path target = new Place(name).make( - this.targetDir.toPath().resolve(ParseMojo.DIR), - TranspileMojo.EXT - ); - tojo.set(AssembleMojo.ATTR_XMIR, target.toAbsolutePath().toString()); - Logger.debug( - this, "Parsed %s to %s", - Save.rel(source), Save.rel(target) - ); - } catch (final IllegalArgumentException ex) { - if (this.failOnError || !ex.getMessage().contains("Failed to parse")) { - throw ex; + } catch (final ParsingException ex) { + if (this.failOnError) { + throw new IllegalArgumentException( + String.format("Failed to parse %s", source), + ex + ); } Logger.warn( - this, "Parse was skipped due to failOnError=false. In file %s with error: %s", - source.toString(), + this, "Parsing was skipped due to failOnError=false. In file %s with error: %s", + source, ex.getMessage() ); + return; } - } - - /** - * Safely extract version attribute. - * @param tojo Source tojo - * @return Version value or empty string if attribute doesn't exist. - */ - private static String verSafe(final Tojo tojo) { - String ver = ParseMojo.ZERO; - if (tojo.exists(AssembleMojo.ATTR_VERSION)) { - ver = tojo.get(AssembleMojo.ATTR_VERSION); - } - return ver; - } - - /** - * Get hash for the version. - * @param ver Version to tag - * @return Version tag - * @todo #1062:30mins Lets introduce new method `HashOfTag.contains()` - * and get rid of exception-driven workflow. We can use new method - * to check the existence of tag to be hashed and behave accordingly. - */ - private static String safeHash(final String ver) { - String hash; - try { - hash = new HashOfTag(ver).narrow(); - } catch (final IllegalArgumentException ex) { - Logger.debug( - ParseMojo.class, - "Unable to get hash for ver %s", - ver - ); - hash = ver; - } - return hash; + final Path target = new Place(name).make( + this.targetDir.toPath().resolve(ParseMojo.DIR), + TranspileMojo.EXT + ); + tojo.set(AssembleMojo.ATTR_XMIR, target.toAbsolutePath().toString()); + Logger.debug( + this, "Parsed %s to %s", + Save.rel(source), Save.rel(target) + ); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index 08ea9546cc..86484d3fc2 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -164,7 +164,7 @@ void testCrashesWithFileName(@TempDir final Path temp) .with("foreignFormat", "csv") .execute() ); - Assertions.assertEquals(exception.getMessage(), String.format("Failed to parse %s", src)); + Assertions.assertEquals(String.format("Failed to parse %s", src), exception.getMessage()); } @Test From cbe17be605ad70b52809a923542a0dba61d8e1d8 Mon Sep 17 00:00:00 2001 From: mximp Date: Mon, 5 Sep 2022 14:44:03 +0300 Subject: [PATCH 15/39] #1062 Remove puzzle, rename `content` --- .../src/main/java/org/eolang/maven/Footprint.java | 5 ++--- .../src/main/java/org/eolang/maven/HashOfTag.java | 3 --- .../src/test/java/org/eolang/maven/FootprintTest.java | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java index afea64c8a1..84b50ce268 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -86,8 +86,7 @@ public Footprint(final String ver, final Path main, final Path cache) { * @return Content of a file * @throws IOException In case of IO issue. */ - @SuppressWarnings("PMD.AvoidCatchingGenericException") - public String content(final String program, final String ext) throws IOException { + public String load(final String program, final String ext) throws IOException { final Path cached = new Place(program).make(this.cache.resolve(this.safeVer()), ext); final Path target = new Place(program).make(this.main, ext); final IoCheckedText content; @@ -121,7 +120,7 @@ public void save(final String program, final String ext, final Scalar co "File found in cache: %s", cached ); - text = this.content(program, ext); + text = this.load(program, ext); } else { text = new IoChecked<>(content).value(); if (Footprint.versioned(this.ver)) { diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java index a94d63a444..81ffe89612 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/HashOfTag.java @@ -34,9 +34,6 @@ /** * Hash of tag. * @since 0.26 - * @todo #1062:30min Make HashOfTag testable without accessing web. - * We need to be able to populate tags with custom values rather than - * always download it from the web. */ final class HashOfTag { diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java index 10ec1087c8..7753555fa7 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java @@ -48,7 +48,7 @@ void testContentOfCachedFile(@TempDir final Path temp) throws Exception { .save("org.eolang.txt.text", "xmir", () -> content); MatcherAssert.assertThat( new Footprint("1.0.0", temp.resolve("target"), temp.resolve("parsed")) - .content("org.eolang.txt.text", "xmir"), + .load("org.eolang.txt.text", "xmir"), Matchers.equalTo(content) ); } @@ -66,7 +66,7 @@ void testContentOfNoCacheFile(final String ver, @TempDir final Path temp) throws .save("org.eolang.txt.text", "xmir", () -> content); MatcherAssert.assertThat( new Footprint("*.*.*", temp.resolve("target"), temp.resolve("parsed")) - .content("org.eolang.txt.text", "xmir"), + .load("org.eolang.txt.text", "xmir"), Matchers.equalTo(content) ); } From dba17db17febe17b577378039df486d9e5a74a69 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 11 Sep 2022 14:08:26 +0300 Subject: [PATCH 16/39] Runtime interrupted exception --- .../src/main/java/org/eolang/AtComposite.java | 3 ++ .../main/java/org/eolang/ExInterrupted.java | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 eo-runtime/src/main/java/org/eolang/ExInterrupted.java diff --git a/eo-runtime/src/main/java/org/eolang/AtComposite.java b/eo-runtime/src/main/java/org/eolang/AtComposite.java index 6e01449fcf..da74ceee0a 100644 --- a/eo-runtime/src/main/java/org/eolang/AtComposite.java +++ b/eo-runtime/src/main/java/org/eolang/AtComposite.java @@ -74,6 +74,9 @@ public Phi get() { // @checkstyle IllegalCatchCheck (3 line) } catch (final RuntimeException ex) { throw ex; + } catch (InterruptedException ex){ + System.out.println("Interrupted Exception"); + throw new ExInterrupted(); } catch (final Throwable ex) { throw new ExFailure( String.format( diff --git a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java new file mode 100644 index 0000000000..59937da92b --- /dev/null +++ b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java @@ -0,0 +1,44 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package org.eolang; + +/** + * Exception to control threads interruptions. + * + * @since 0.28.3 + */ +public class ExInterrupted extends ExAbstract{ + /** + * Serialization identifier. + */ + private static final long serialVersionUID = 2377580403532765676L; + + /** + * Ctor. + */ + public ExInterrupted(){ + super(); + } +} From ca12fcaca0634daafc725b108c9e7ec299555841 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 11 Sep 2022 14:14:53 +0300 Subject: [PATCH 17/39] violations --- eo-runtime/src/main/java/org/eolang/AtComposite.java | 2 +- eo-runtime/src/main/java/org/eolang/ExInterrupted.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/AtComposite.java b/eo-runtime/src/main/java/org/eolang/AtComposite.java index da74ceee0a..4457f553d4 100644 --- a/eo-runtime/src/main/java/org/eolang/AtComposite.java +++ b/eo-runtime/src/main/java/org/eolang/AtComposite.java @@ -74,7 +74,7 @@ public Phi get() { // @checkstyle IllegalCatchCheck (3 line) } catch (final RuntimeException ex) { throw ex; - } catch (InterruptedException ex){ + } catch (final InterruptedException ex) { System.out.println("Interrupted Exception"); throw new ExInterrupted(); } catch (final Throwable ex) { diff --git a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java index 59937da92b..d9a554442f 100644 --- a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java +++ b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java @@ -29,7 +29,7 @@ * * @since 0.28.3 */ -public class ExInterrupted extends ExAbstract{ +public class ExInterrupted extends ExAbstract { /** * Serialization identifier. */ @@ -38,7 +38,7 @@ public class ExInterrupted extends ExAbstract{ /** * Ctor. */ - public ExInterrupted(){ + public ExInterrupted() { super(); } } From a6e7addd38208628d23d02881bde9d3e3c453fbd Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 11 Sep 2022 14:28:43 +0300 Subject: [PATCH 18/39] swapped catches --- eo-runtime/src/main/java/org/eolang/AtComposite.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/AtComposite.java b/eo-runtime/src/main/java/org/eolang/AtComposite.java index 4457f553d4..713d99cbe9 100644 --- a/eo-runtime/src/main/java/org/eolang/AtComposite.java +++ b/eo-runtime/src/main/java/org/eolang/AtComposite.java @@ -71,12 +71,12 @@ public Attr copy(final Phi self) { public Phi get() { try { return this.expr.get(this.rho); - // @checkstyle IllegalCatchCheck (3 line) - } catch (final RuntimeException ex) { - throw ex; } catch (final InterruptedException ex) { System.out.println("Interrupted Exception"); throw new ExInterrupted(); + // @checkstyle IllegalCatchCheck (3 line) + } catch (final RuntimeException ex) { + throw ex; } catch (final Throwable ex) { throw new ExFailure( String.format( From 9bd64c120df2aa1ede199d043ae2d8e9b8268cb3 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Sun, 11 Sep 2022 14:47:34 +0300 Subject: [PATCH 19/39] removed default ctor --- eo-runtime/src/main/java/org/eolang/ExInterrupted.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java index d9a554442f..35e45bbc6c 100644 --- a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java +++ b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java @@ -35,10 +35,4 @@ public class ExInterrupted extends ExAbstract { */ private static final long serialVersionUID = 2377580403532765676L; - /** - * Ctor. - */ - public ExInterrupted() { - super(); - } } From aa92bfcb9d0a1488dbece50cc7125097199f90de Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 12 Sep 2022 09:21:40 +0300 Subject: [PATCH 20/39] removed print --- eo-runtime/src/main/java/org/eolang/AtComposite.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eo-runtime/src/main/java/org/eolang/AtComposite.java b/eo-runtime/src/main/java/org/eolang/AtComposite.java index 713d99cbe9..d028862444 100644 --- a/eo-runtime/src/main/java/org/eolang/AtComposite.java +++ b/eo-runtime/src/main/java/org/eolang/AtComposite.java @@ -72,7 +72,6 @@ public Phi get() { try { return this.expr.get(this.rho); } catch (final InterruptedException ex) { - System.out.println("Interrupted Exception"); throw new ExInterrupted(); // @checkstyle IllegalCatchCheck (3 line) } catch (final RuntimeException ex) { From e68f61b2b6f4a551addb3cd83026746708e7c6a0 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 12 Sep 2022 09:34:42 +0300 Subject: [PATCH 21/39] added Ctor --- eo-runtime/src/main/java/org/eolang/ExInterrupted.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java index 35e45bbc6c..a85fff42f2 100644 --- a/eo-runtime/src/main/java/org/eolang/ExInterrupted.java +++ b/eo-runtime/src/main/java/org/eolang/ExInterrupted.java @@ -35,4 +35,10 @@ public class ExInterrupted extends ExAbstract { */ private static final long serialVersionUID = 2377580403532765676L; + /** + * Ctor. + */ + public ExInterrupted() { + super(null); + } } From b73f6ae7ae7debc1e2ea40f990a85c1719a21719 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 12 Sep 2022 11:58:19 +0300 Subject: [PATCH 22/39] Interrupt again --- eo-runtime/src/main/java/org/eolang/AtComposite.java | 1 + 1 file changed, 1 insertion(+) diff --git a/eo-runtime/src/main/java/org/eolang/AtComposite.java b/eo-runtime/src/main/java/org/eolang/AtComposite.java index d028862444..60fc8c1733 100644 --- a/eo-runtime/src/main/java/org/eolang/AtComposite.java +++ b/eo-runtime/src/main/java/org/eolang/AtComposite.java @@ -72,6 +72,7 @@ public Phi get() { try { return this.expr.get(this.rho); } catch (final InterruptedException ex) { + Thread.currentThread().interrupt(); throw new ExInterrupted(); // @checkstyle IllegalCatchCheck (3 line) } catch (final RuntimeException ex) { From 169accb56c9c0ea572307fd2b73c753687b9ca83 Mon Sep 17 00:00:00 2001 From: mximp Date: Mon, 12 Sep 2022 14:01:16 +0300 Subject: [PATCH 23/39] #1062 cache parsed by hash --- .../java/org/eolang/maven/AssembleMojo.java | 5 ++ .../main/java/org/eolang/maven/Footprint.java | 50 ++++++++----------- .../main/java/org/eolang/maven/ParseMojo.java | 25 +++++++--- .../main/java/org/eolang/maven/PullMojo.java | 6 ++- 4 files changed, 51 insertions(+), 35 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java index 5ec07a8080..d85bc3a2d1 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java @@ -94,6 +94,11 @@ public final class AssembleMojo extends SafeMojo { */ public static final String ATTR_SCOPE = "scope"; + /** + * Tojo ATTR. + */ + public static final String ATTR_HASH = "hash"; + /** * Output. * @checkstyle MemberNameCheck (7 lines) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java index 84b50ce268..f231a2b055 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java @@ -35,8 +35,7 @@ * Program footprint of EO compilation process. *

The footprint consists of file in {@link #main} folder and optionally cached * file in {@link #cache} folder. - * Caching is applied if {@link #ver} represents true version in terms of - * {@link #versioned(String)} method. + * Caching is applied if {@link #hash} is not empty otherwise caching is ignored. *

Usage example: * *

@@ -60,7 +59,7 @@ public class Footprint {
     /**
      * Version tag.
      */
-    private final String ver;
+    private final String hash;
 
     /**
      * Path to cache root.
@@ -69,12 +68,12 @@ public class Footprint {
 
     /**
      * Ctor.
-     * @param ver Version tag
+     * @param hash Version tag
      * @param main Main root
      * @param cache Cache root
      */
-    public Footprint(final String ver, final Path main, final Path cache) {
-        this.ver = ver;
+    public Footprint(final String hash, final Path main, final Path cache) {
+        this.hash = hash;
         this.main = main;
         this.cache = cache;
     }
@@ -87,10 +86,10 @@ public Footprint(final String ver, final Path main, final Path cache) {
      * @throws IOException In case of IO issue.
      */
     public String load(final String program, final String ext) throws IOException {
-        final Path cached = new Place(program).make(this.cache.resolve(this.safeVer()), ext);
+        final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext);
         final Path target = new Place(program).make(this.main, ext);
         final IoCheckedText content;
-        if (Footprint.versioned(this.ver) && cached.toFile().exists()) {
+        if (!this.hash.isEmpty() && cached.toFile().exists()) {
             content = new IoCheckedText(
                 new TextOf(cached)
             );
@@ -111,19 +110,26 @@ public String load(final String program, final String ext) throws IOException {
      */
     public void save(final String program, final String ext, final Scalar content)
         throws IOException {
-        final Path cached = new Place(program).make(this.cache.resolve(this.safeVer()), ext);
+        final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext);
         final Path target = new Place(program).make(this.main, ext);
         final String text;
-        if (Footprint.versioned(this.ver) && cached.toFile().exists()) {
+        if (!this.hash.isEmpty() && cached.toFile().exists()) {
             Logger.info(
                 this,
-                "File found in cache: %s",
+                "Program %s found in cache: %s",
+                program,
                 cached
             );
             text = this.load(program, ext);
         } else {
             text = new IoChecked<>(content).value();
-            if (Footprint.versioned(this.ver)) {
+            Logger.info(
+                this,
+                "Parsed program %s into cache: %s",
+                program,
+                cached
+            );
+            if (!this.hash.isEmpty()) {
                 new Save(
                     text,
                     cached
@@ -137,22 +143,10 @@ public void save(final String program, final String ext, final Scalar co
     }
 
     /**
-     * Transform version for legal path.
-     * @return Version tag
-     */
-    private String safeVer() {
-        return this.ver.replaceAll("[* ]", "_");
-    }
-
-    /**
-     * Is it a true version?
-     * @param ver Version to check
-     * @return True if version has meaningful value and false otherwise
+     * Transform hash for legal path.
+     * @return Hash
      */
-    private static boolean versioned(final String ver) {
-        final String trimmed = ver.trim();
-        return !trimmed.isEmpty()
-            && !trimmed.equals("0.0.0")
-            && !trimmed.equals("*.*.*");
+    private String safeHash() {
+        return this.hash.replaceAll("[* ]", "_");
     }
 }
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
index d1da5cb38f..c8f51e101b 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
@@ -128,14 +128,14 @@ public void exec() throws IOException {
     private void parse(final Tojo tojo) throws IOException {
         final Path source = Paths.get(tojo.get(AssembleMojo.ATTR_EO));
         final String name = tojo.get(Tojos.KEY);
-        final String version;
-        if (tojo.exists(AssembleMojo.ATTR_VERSION)) {
-            version = tojo.get(AssembleMojo.ATTR_VERSION);
+        final String hash;
+        if (tojo.exists(AssembleMojo.ATTR_HASH)) {
+            hash = tojo.get(AssembleMojo.ATTR_HASH);
         } else {
-            version = ParseMojo.ZERO;
+            hash = "";
         }
         final Footprint footprint = new Footprint(
-            version,
+            hash,
             this.targetDir.toPath().resolve(ParseMojo.DIR),
             this.cache
         );
@@ -144,13 +144,19 @@ private void parse(final Tojo tojo) throws IOException {
                 name,
                 AssembleMojo.ATTR_XMIR,
                 () -> {
+                    Logger.info(
+                        this,
+                        "Parsing program %s from source %s",
+                        name,
+                        source
+                    );
                     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                     new Syntax(
                         name,
                         new InputOf(source),
                         new OutputTo(baos)
                     ).parse();
-                    return new XMLDocument(
+                    final String parsed = new XMLDocument(
                         new Xembler(
                             new Directives().xpath("/program").attr(
                                 "source",
@@ -158,6 +164,13 @@ private void parse(final Tojo tojo) throws IOException {
                             )
                         ).applyQuietly(new XMLDocument(baos.toByteArray()).node())
                     ).toString();
+                    Logger.info(
+                        this,
+                        "Parsed program %s:\n %s",
+                        name,
+                        parsed
+                        );
+                    return parsed;
                 }
             );
         } catch (final ParsingException ex) {
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
index af055bad66..cb439b21aa 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
@@ -88,8 +88,8 @@ public void exec() throws IOException {
             row -> !row.exists(AssembleMojo.ATTR_EO)
                 && !row.exists(AssembleMojo.ATTR_XMIR)
         );
+        final HashOfTag tag = new HashOfTag(this.hash);
         if (this.objectionary == null) {
-            final HashOfTag tag = new HashOfTag(this.hash);
             this.objectionary = new OyFallbackSwap(
                 new OyHome(
                     tag.narrow(),
@@ -109,6 +109,10 @@ public void exec() throws IOException {
                     AssembleMojo.ATTR_EO,
                     this.pull(tojo.get(Tojos.KEY)).toAbsolutePath().toString()
                 );
+                tojo.set(
+                    AssembleMojo.ATTR_HASH,
+                    tag.narrow()
+                );
             }
             Logger.info(
                 this, "%d program(s) pulled from %s",

From eaa9169848621f08b35b01acd80e6b8ea598a0e1 Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Mon, 12 Sep 2022 12:56:01 +0000
Subject: [PATCH 24/39] Update yegor256/latexmk-action action to v0.5.0

---
 .github/workflows/latexmk.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.github/workflows/latexmk.yml b/.github/workflows/latexmk.yml
index 0d3da7b29f..dbd96004a1 100644
--- a/.github/workflows/latexmk.yml
+++ b/.github/workflows/latexmk.yml
@@ -11,7 +11,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
-      - uses: yegor256/latexmk-action@0.4.0
+      - uses: yegor256/latexmk-action@0.5.0
         with:
           path: paper
           opts: -pdf

From 1e98e2d15d30d5a3650d7cb1db221417e3a0534a Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 12 Sep 2022 18:02:04 +0300
Subject: [PATCH 25/39] added test

---
 .../java/org/eolang/ExInterruptedTest.java    | 75 +++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java

diff --git a/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java b/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
new file mode 100644
index 0000000000..914d0f492b
--- /dev/null
+++ b/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
@@ -0,0 +1,75 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016-2022 Objectionary.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package org.eolang;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test case for {@link ExInterrupted}.
+ *
+ * @since 0.28.3
+ */
+public class ExInterruptedTest {
+
+    @Test
+    void rightException() {
+        final EOthrow phi = new EOthrow(new Data.ToPhi(true));
+        try {
+            new Dataized(phi.attr("φ").get()).take();
+        // @checkstyle IllegalCatchCheck (3 line)
+        } catch (final Exception ex) {
+            MatcherAssert.assertThat(
+                ex,
+                Matchers.instanceOf(ExInterrupted.class)
+            );
+        }
+    }
+
+    /**
+     * Phi object that throw InterruptedException.
+     *
+     * @since 0.28.3
+     */
+    private static class EOthrow extends PhDefault {
+        /**
+         * CTor.
+         * @param sigma Sigma
+         */
+        EOthrow(final Phi sigma) {
+            super(sigma);
+            this.add(
+                "φ",
+                new AtComposite(
+                    this,
+                    rho -> {
+                        throw new InterruptedException();
+                    }
+                )
+            );
+        }
+
+    }
+}

From b43719a3d96d4fee9d57f5226ccf08277de5d308 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 12 Sep 2022 18:18:20 +0300
Subject: [PATCH 26/39] AssertThrows

---
 .../src/test/java/org/eolang/ExInterruptedTest.java | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java b/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
index 914d0f492b..74ebb623d5 100644
--- a/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
+++ b/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
@@ -23,8 +23,7 @@
  */
 package org.eolang;
 
-import org.hamcrest.MatcherAssert;
-import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -37,15 +36,7 @@ public class ExInterruptedTest {
     @Test
     void rightException() {
         final EOthrow phi = new EOthrow(new Data.ToPhi(true));
-        try {
-            new Dataized(phi.attr("φ").get()).take();
-        // @checkstyle IllegalCatchCheck (3 line)
-        } catch (final Exception ex) {
-            MatcherAssert.assertThat(
-                ex,
-                Matchers.instanceOf(ExInterrupted.class)
-            );
-        }
+        Assertions.assertThrows(ExInterrupted.class, () -> new Dataized(phi.attr("φ").get()).take());
     }
 
     /**

From b5fb60834b33829d3f8b2f2e6fbe308738a22146 Mon Sep 17 00:00:00 2001
From: levBagryansky <28lev11@gmail.com>
Date: Mon, 12 Sep 2022 18:21:05 +0300
Subject: [PATCH 27/39] violation

---
 eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java b/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
index 74ebb623d5..69c84b8a2a 100644
--- a/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
+++ b/eo-runtime/src/test/java/org/eolang/ExInterruptedTest.java
@@ -36,7 +36,10 @@ public class ExInterruptedTest {
     @Test
     void rightException() {
         final EOthrow phi = new EOthrow(new Data.ToPhi(true));
-        Assertions.assertThrows(ExInterrupted.class, () -> new Dataized(phi.attr("φ").get()).take());
+        Assertions.assertThrows(
+            ExInterrupted.class,
+            () -> new Dataized(phi.attr("φ").get()).take()
+        );
     }
 
     /**

From e5fc5a597db2fd7bb8e238f16d24f1f3a0a0a70c Mon Sep 17 00:00:00 2001
From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com>
Date: Mon, 12 Sep 2022 17:07:06 +0000
Subject: [PATCH 28/39] Update dependency org.yaml:snakeyaml to v1.32

---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 48d27be83b..8c8e11d86f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -153,7 +153,7 @@ SOFTWARE.
       
         org.yaml
         snakeyaml
-        1.31
+        1.32
       
       
         com.jcabi

From 74fb8aead94b4575a97b782ccb784cd2095e08cb Mon Sep 17 00:00:00 2001
From: mximp 
Date: Tue, 13 Sep 2022 10:01:17 +0300
Subject: [PATCH 29/39] #1062 correct tests env + prop in AssembleMojo

---
 .../src/main/java/org/eolang/maven/AssembleMojo.java |  9 +++++++++
 .../src/main/java/org/eolang/maven/Footprint.java    |  8 +-------
 .../src/main/java/org/eolang/maven/ParseMojo.java    | 12 +++---------
 .../test/java/org/eolang/maven/AssembleMojoTest.java |  2 ++
 .../test/java/org/eolang/maven/FootprintTest.java    |  8 ++++----
 .../src/test/java/org/eolang/maven/GmiMojoTest.java  |  1 +
 .../test/java/org/eolang/maven/OptimizeMojoTest.java |  4 ++++
 .../test/java/org/eolang/maven/ParseMojoTest.java    |  6 +++++-
 .../test/java/org/eolang/maven/ResolveMojoTest.java  |  3 +++
 .../java/org/eolang/maven/TranspileMojoTest.java     |  4 ++++
 10 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java
index d85bc3a2d1..5a5aaf0aab 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java
@@ -27,6 +27,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.function.BiConsumer;
@@ -174,6 +175,14 @@ public final class AssembleMojo extends SafeMojo {
         defaultValue = "true")
     private boolean failOnError = true;
 
+    /**
+     * Parsed cache directory.
+     * @checkstyle MemberNameCheck (7 lines)
+     */
+    @Parameter(property = "eo.parsed.cache")
+    @SuppressWarnings("PMD.ImmutableField")
+    private Path parsedCache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed");
+
     @Override
     public void exec() throws IOException {
         if (this.central == null) {
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java
index f231a2b055..6898e19101 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java
@@ -40,7 +40,7 @@
  * 
  *  
  *    final Footprint footprint = new Footprint(
- *      version,
+ *      hash,
  *      targetRoot,
  *      cacheRoot
  *    ).save(program, ext);
@@ -123,12 +123,6 @@ public void save(final String program, final String ext, final Scalar co
             text = this.load(program, ext);
         } else {
             text = new IoChecked<>(content).value();
-            Logger.info(
-                this,
-                "Parsed program %s into cache: %s",
-                program,
-                cached
-            );
             if (!this.hash.isEmpty()) {
                 new Save(
                     text,
diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
index c8f51e101b..749ec577bd 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
@@ -73,7 +73,7 @@ public final class ParseMojo extends SafeMojo {
      */
     @Parameter(property = "eo.parsed.cache")
     @SuppressWarnings("PMD.ImmutableField")
-    private Path cache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed");
+    private Path parsedCache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed");
 
     /**
      * Whether we should fail on parsing error.
@@ -137,19 +137,13 @@ private void parse(final Tojo tojo) throws IOException {
         final Footprint footprint = new Footprint(
             hash,
             this.targetDir.toPath().resolve(ParseMojo.DIR),
-            this.cache
+            this.parsedCache
         );
         try {
             footprint.save(
                 name,
                 AssembleMojo.ATTR_XMIR,
                 () -> {
-                    Logger.info(
-                        this,
-                        "Parsing program %s from source %s",
-                        name,
-                        source
-                    );
                     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                     new Syntax(
                         name,
@@ -169,7 +163,7 @@ private void parse(final Tojo tojo) throws IOException {
                         "Parsed program %s:\n %s",
                         name,
                         parsed
-                        );
+                    );
                     return parsed;
                 }
             );
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java
index 86a5e91201..1c8cabe5ec 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java
@@ -64,6 +64,7 @@ void assemblesTogether(@TempDir final Path temp) throws Exception {
             .with("foreign", temp.resolve("eo-foreign.json").toFile())
             .with("foreignFormat", "json")
             .with("placed", temp.resolve("list").toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("skipZeroVersions", true)
             .with(
                 "objectionary",
@@ -121,6 +122,7 @@ void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws Except
             .with("foreign", temp.resolve("eo-foreign.json").toFile())
             .with("foreignFormat", "json")
             .with("placed", temp.resolve("list").toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("skipZeroVersions", true)
             .with("failOnError", false)
             .with(
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java
index 7753555fa7..a2ef1451d0 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java
@@ -44,16 +44,16 @@ void testContentOfCachedFile(@TempDir final Path temp) throws Exception {
             "",
             ""
         );
-        new Footprint("1.0.0", temp.resolve("target"), temp.resolve("parsed"))
+        new Footprint("abcde123", temp.resolve("target"), temp.resolve("parsed"))
             .save("org.eolang.txt.text", "xmir", () -> content);
         MatcherAssert.assertThat(
-            new Footprint("1.0.0", temp.resolve("target"), temp.resolve("parsed"))
+            new Footprint("abcde123", temp.resolve("target"), temp.resolve("parsed"))
                 .load("org.eolang.txt.text", "xmir"),
             Matchers.equalTo(content)
         );
     }
 
-    @ValueSource(strings = {"0.0.0", "*.*.*", "", "   "})
+    @ValueSource(strings = {"", "   "})
     @ParameterizedTest
     void testContentOfNoCacheFile(final String ver, @TempDir final Path temp) throws Exception {
         final String content = String.join(
@@ -65,7 +65,7 @@ void testContentOfNoCacheFile(final String ver, @TempDir final Path temp) throws
         new Footprint(ver, temp.resolve("target"), temp.resolve("parsed"))
             .save("org.eolang.txt.text", "xmir", () -> content);
         MatcherAssert.assertThat(
-            new Footprint("*.*.*", temp.resolve("target"), temp.resolve("parsed"))
+            new Footprint("", temp.resolve("target"), temp.resolve("parsed"))
                 .load("org.eolang.txt.text", "xmir"),
             Matchers.equalTo(content)
         );
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java
index 27b770aa1f..ea01402e37 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java
@@ -140,6 +140,7 @@ private static String toXembly(final String code) throws IOException {
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .execute();
         new Moja<>(OptimizeMojo.class)
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java
index b76ba82b85..7b7831d7f9 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java
@@ -57,6 +57,7 @@ void skipsAlreadyOptimized(@TempDir final Path temp) throws Exception {
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .execute();
         new Moja<>(OptimizeMojo.class)
@@ -96,6 +97,7 @@ void optimizesIfExpired(@TempDir final Path temp) throws Exception {
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
             .with("foreignFormat", "csv")
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .execute();
         new Moja<>(OptimizeMojo.class)
             .with("targetDir", target.toFile())
@@ -136,6 +138,7 @@ void testSimpleOptimize(@TempDir final Path temp) throws Exception {
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
             .with("foreignFormat", "csv")
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .execute();
         new Moja<>(OptimizeMojo.class)
             .with("targetDir", target.toFile())
@@ -184,6 +187,7 @@ void testOptimizeWithFailOnErrorFlag(@TempDir final Path temp) throws Exception
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
             .with("foreignFormat", "csv")
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .execute();
         new Moja<>(OptimizeMojo.class)
             .with("targetDir", target.toFile())
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java
index 86484d3fc2..f4df38617b 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java
@@ -61,6 +61,7 @@ void testSimpleParsing(@TempDir final Path temp) throws Exception {
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .execute();
         MatcherAssert.assertThat(
@@ -108,7 +109,7 @@ void testSimpleParsingCached(@TempDir final Path temp) throws Exception {
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
             .with("foreignFormat", "csv")
-            .with("cache", temp.resolve("parsed"))
+            .with("parsedCache", temp.resolve("parsed"))
             .execute();
         MatcherAssert.assertThat(
             Files.exists(
@@ -141,6 +142,7 @@ void testCrashOnInvalidSyntax(@TempDir final Path temp)
             () -> new Moja<>(ParseMojo.class)
                 .with("targetDir", temp.resolve("target").toFile())
                 .with("foreign", foreign.toFile())
+                .with("parsedCache", temp.resolve("cache/parsed"))
                 .with("foreignFormat", "csv")
                 .execute()
         );
@@ -161,6 +163,7 @@ void testCrashesWithFileName(@TempDir final Path temp)
             () -> new Moja<>(ParseMojo.class)
                 .with("targetDir", temp.resolve("target").toFile())
                 .with("foreign", foreign.toFile())
+                .with("parsedCache", temp.resolve("cache/parsed"))
                 .with("foreignFormat", "csv")
                 .execute()
         );
@@ -185,6 +188,7 @@ void testDoNotCrashesWithFailOnError(@TempDir final Path temp)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
             .with("foreignFormat", "csv")
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("failOnError", false)
             .execute();
         MatcherAssert.assertThat(
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java
index 2a61633c7f..327bf8be97 100644
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java
@@ -53,6 +53,7 @@ void testSimpleResolve(@TempDir final Path temp) throws Exception {
         new Moja<>(ParseMojo.class)
             .with("foreign", foreign.toFile())
             .with("targetDir", target.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .execute();
         new Moja<>(OptimizeMojo.class)
             .with("targetDir", target.toFile())
@@ -109,6 +110,7 @@ void testConflictingDependencies(@TempDir final Path temp) throws IOException {
         new Moja<>(ParseMojo.class)
             .with("foreign", foreign.toFile())
             .with("targetDir", target.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .execute();
         new Moja<>(OptimizeMojo.class)
             .with("targetDir", target.toFile())
@@ -168,6 +170,7 @@ void testConflictingDependenciesNoFail(@TempDir final Path temp) throws IOExcept
         new Moja<>(ParseMojo.class)
             .with("foreign", foreign.toFile())
             .with("targetDir", target.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .execute();
         new Moja<>(OptimizeMojo.class)
             .with("targetDir", target.toFile())
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java
index a19f394284..0dcc138684 100755
--- a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java
@@ -72,6 +72,7 @@ void recompilesIfExpired(@TempDir final Path temp)
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .execute();
         new Moja<>(OptimizeMojo.class)
@@ -125,6 +126,7 @@ void testFailOnWarning(@TempDir final Path temp) throws Exception {
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .execute();
         new Moja<>(OptimizeMojo.class)
@@ -173,6 +175,7 @@ void testFailOnError(@TempDir final Path temp) throws Exception {
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .with("failOnError", false)
             .execute();
@@ -259,6 +262,7 @@ private Path compileToFile(
         new Moja<>(ParseMojo.class)
             .with("targetDir", target.toFile())
             .with("foreign", foreign.toFile())
+            .with("parsedCache", temp.resolve("cache/parsed"))
             .with("foreignFormat", "csv")
             .execute();
         new Moja<>(OptimizeMojo.class)

From 0417ceff04608bff1ecbc8d42a39d0ddf4423166 Mon Sep 17 00:00:00 2001
From: graur 
Date: Tue, 13 Sep 2022 12:14:14 +0300
Subject: [PATCH 30/39] #1212 - made memory return value instead of TRUE

---
 .../main/java/EOorg/EOeolang/EOmemory.java    | 13 ++++-----
 .../src/test/eo/org/eolang/bool-tests.eo      | 28 ++++++++++---------
 .../src/test/eo/org/eolang/memory-tests.eo    |  4 ++-
 .../src/test/eo/org/eolang/runtime-tests.eo   |  2 +-
 .../java/EOorg/EOeolang/EOmemoryTest.java     | 18 ++++++------
 5 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java
index 4b09d285a3..dcd05fd824 100644
--- a/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java
+++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java
@@ -73,14 +73,13 @@ private final class Write extends PhDefault {
                 new AtComposite(
                     this,
                     rho -> {
-                        rho.attr("σ").get().attr("enclosure").put(
-                            new Data.ToPhi(
-                                new Dataized(
-                                    rho.attr("x").get()
-                                ).take()
-                            )
+                        Phi phi = new Data.ToPhi(
+                            new Dataized(
+                                rho.attr("x").get()
+                            ).take()
                         );
-                        return new Data.ToPhi(true);
+                        rho.attr("σ").get().attr("enclosure").put(phi);
+                        return phi;
                     }
                 )
             );
diff --git a/eo-runtime/src/test/eo/org/eolang/bool-tests.eo b/eo-runtime/src/test/eo/org/eolang/bool-tests.eo
index 1a8205d845..f4dcedaaf2 100644
--- a/eo-runtime/src/test/eo/org/eolang/bool-tests.eo
+++ b/eo-runtime/src/test/eo/org/eolang/bool-tests.eo
@@ -64,9 +64,11 @@
   memory 0 > x
   assert-that > @
     and.
-      x.write 5
       eq.
-        TRUE
+        x.write 5
+        5
+      eq.
+        11
         while.
           x.lt 10
           [i]
@@ -99,15 +101,15 @@
     and.
       not.
         and.
-          (mFirst.write 1).not
-          mFirst.write 2
-          mFirst.write 3
+          (mFirst.write 1).eq 100
+          (mFirst.write 2).eq 2
+          (mFirst.write 3).eq 3
       not.
         and.
-          mThird.write 1
-          mThird.write 2
-          (mThird.write 3).not
-          (mThird.write 4)
+          (mThird.write 1).eq 1
+          (mThird.write 2).eq 2
+          (mThird.write 3).eq 300
+          (mThird.write 4).eq 4
       mFirst.eq 1
       mThird.eq 3
     $.equal-to TRUE
@@ -120,13 +122,13 @@
   assert-that > @
     and.
       or.
-        mFirst.write 1
+        (mFirst.write 1).eq 1
         mFirst.write 2
         mFirst.write 3
       or.
-        (mThird.write 1).not
-        (mThird.write 2).not
-        mThird.write 3
+        (mThird.write 1).eq 100
+        (mThird.write 2).eq 200
+        (mThird.write 3).eq 3
         mThird.write 4
       mFirst.eq 1
       mThird.eq 3
diff --git a/eo-runtime/src/test/eo/org/eolang/memory-tests.eo b/eo-runtime/src/test/eo/org/eolang/memory-tests.eo
index 9a79371872..862a4009c0 100644
--- a/eo-runtime/src/test/eo/org/eolang/memory-tests.eo
+++ b/eo-runtime/src/test/eo/org/eolang/memory-tests.eo
@@ -73,7 +73,9 @@
     and.
       seq
         a.write 10
-        b.write 20
+        eq.
+          b.write 20
+          20
       a.eq 10
     $.equal-to TRUE
 
diff --git a/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo b/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo
index 6fb8bd84b2..97decaf690 100644
--- a/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo
+++ b/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo
@@ -104,7 +104,7 @@
         x.while
           [i]
             &.x.write FALSE > @
-    $.equal-to TRUE
+    $.equal-to FALSE
 
 [] > calculates-only-once-BROKEN
   memory 0 > x
diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOmemoryTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOmemoryTest.java
index 38eec0b6d3..3cc99e2d18 100644
--- a/eo-runtime/src/test/java/EOorg/EOeolang/EOmemoryTest.java
+++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOmemoryTest.java
@@ -66,7 +66,7 @@ public void readsAndWrites() {
         final Phi text = new Data.ToPhi("Hello, world!");
         final Phi write = mem.attr(EOmemoryTest.WRITE).get();
         write.attr(0).put(text);
-        new Dataized(write).take(Boolean.class);
+        new Dataized(write).take(String.class);
         MatcherAssert.assertThat(
             new Dataized(mem).take(String.class),
             Matchers.startsWith("Hello, ")
@@ -81,7 +81,7 @@ public void comparesForEquality() {
                 new PhCopy(new PhMethod(mem, EOmemoryTest.WRITE)),
                 0, new Data.ToPhi(1L)
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         MatcherAssert.assertThat(
             new Dataized(
                 new PhWith(
@@ -102,7 +102,7 @@ public void writesAndRewrites() {
                 new PhCopy(new PhMethod(mem, EOmemoryTest.WRITE)),
                 0, new Data.ToPhi(1L)
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         MatcherAssert.assertThat(
             new Dataized(mem).take(Long.class),
             Matchers.equalTo(1L)
@@ -112,7 +112,7 @@ public void writesAndRewrites() {
                 new PhCopy(new PhMethod(mem, EOmemoryTest.WRITE)),
                 0, new Data.ToPhi(5L)
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         MatcherAssert.assertThat(
             new Dataized(mem).take(Long.class),
             Matchers.equalTo(5L)
@@ -125,7 +125,7 @@ public void makeCorrectCopy() {
         final Phi text = new Data.ToPhi(1L);
         final Phi write = mem.attr(EOmemoryTest.WRITE).get();
         write.attr(0).put(text);
-        new Dataized(write).take(Boolean.class);
+        new Dataized(write).take(Long.class);
         MatcherAssert.assertThat(
             new Dataized(new PhCopy(mem)).take(Long.class),
             Matchers.equalTo(1L)
@@ -161,7 +161,7 @@ public void comparesOnFly() {
                 new PhCopy(new PhMethod(mem, EOmemoryTest.WRITE)),
                 0, new Data.ToPhi(1L)
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         final Phi less = new PhWith(
             new PhCopy(new PhMethod(mem, "lt")),
             0, new Data.ToPhi(10L)
@@ -175,7 +175,7 @@ public void comparesOnFly() {
                 new PhCopy(new PhMethod(mem, EOmemoryTest.WRITE)),
                 0, new Data.ToPhi(42L)
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         MatcherAssert.assertThat(
             new Dataized(less).take(Boolean.class),
             Matchers.equalTo(false)
@@ -191,7 +191,7 @@ public void rewritesItself() {
                 0,
                 new Data.ToPhi(1L)
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         new Dataized(
             new PhWith(
                 new PhCopy(new PhMethod(mem, EOmemoryTest.WRITE)),
@@ -201,7 +201,7 @@ public void rewritesItself() {
                     0, new Data.ToPhi(42L)
                 )
             )
-        ).take(Boolean.class);
+        ).take(Long.class);
         MatcherAssert.assertThat(
             new Dataized(mem).take(Long.class),
             Matchers.equalTo(43L)

From ce6f38bf59b95c410c680c0b05ef674a4027c643 Mon Sep 17 00:00:00 2001
From: mximp 
Date: Tue, 13 Sep 2022 14:24:35 +0300
Subject: [PATCH 31/39] #1062 Extract Footprint interface

---
 .../main/java/org/eolang/maven/Footprint.java | 101 +-------------
 .../main/java/org/eolang/maven/FtCached.java  | 126 ++++++++++++++++++
 .../main/java/org/eolang/maven/FtDefault.java |  69 ++++++++++
 .../main/java/org/eolang/maven/ParseMojo.java |  17 +--
 .../{FootprintTest.java => FtCachedTest.java} |  26 +---
 .../java/org/eolang/maven/FtDefaultTest.java  |  53 ++++++++
 .../java/org/eolang/maven/ParseMojoTest.java  |   2 +-
 7 files changed, 265 insertions(+), 129 deletions(-)
 create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java
 create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/FtDefault.java
 rename eo-maven-plugin/src/test/java/org/eolang/maven/{FootprintTest.java => FtCachedTest.java} (65%)
 create mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/FtDefaultTest.java

diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java
index 6898e19101..f32fe344ed 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Footprint.java
@@ -23,60 +23,14 @@
  */
 package org.eolang.maven;
 
-import com.jcabi.log.Logger;
 import java.io.IOException;
-import java.nio.file.Path;
 import org.cactoos.Scalar;
-import org.cactoos.scalar.IoChecked;
-import org.cactoos.text.IoCheckedText;
-import org.cactoos.text.TextOf;
 
 /**
  * Program footprint of EO compilation process.
- * 

The footprint consists of file in {@link #main} folder and optionally cached - * file in {@link #cache} folder. - * Caching is applied if {@link #hash} is not empty otherwise caching is ignored. - *

Usage example: - * - *

- *    final Footprint footprint = new Footprint(
- *      hash,
- *      targetRoot,
- *      cacheRoot
- *    ).save(program, ext);
- *
- *    String content = footprint.content(program, ext);
- *  
- * * @since 1.0 */ -public class Footprint { - /** - * Path to target root. - */ - private final Path main; - - /** - * Version tag. - */ - private final String hash; - - /** - * Path to cache root. - */ - private final Path cache; - - /** - * Ctor. - * @param hash Version tag - * @param main Main root - * @param cache Cache root - */ - public Footprint(final String hash, final Path main, final Path cache) { - this.hash = hash; - this.main = main; - this.cache = cache; - } +public interface Footprint { /** * Get program content of a specific type. @@ -85,21 +39,7 @@ public Footprint(final String hash, final Path main, final Path cache) { * @return Content of a file * @throws IOException In case of IO issue. */ - public String load(final String program, final String ext) throws IOException { - final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext); - final Path target = new Place(program).make(this.main, ext); - final IoCheckedText content; - if (!this.hash.isEmpty() && cached.toFile().exists()) { - content = new IoCheckedText( - new TextOf(cached) - ); - } else { - content = new IoCheckedText( - new TextOf(target) - ); - } - return content.asString(); - } + String load(String program, String ext) throws IOException; /** * Save content. @@ -108,39 +48,6 @@ public String load(final String program, final String ext) throws IOException { * @param content File content * @throws IOException In case of IO issues */ - public void save(final String program, final String ext, final Scalar content) - throws IOException { - final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext); - final Path target = new Place(program).make(this.main, ext); - final String text; - if (!this.hash.isEmpty() && cached.toFile().exists()) { - Logger.info( - this, - "Program %s found in cache: %s", - program, - cached - ); - text = this.load(program, ext); - } else { - text = new IoChecked<>(content).value(); - if (!this.hash.isEmpty()) { - new Save( - text, - cached - ).save(); - } - } - new Save( - text, - target - ).save(); - } - - /** - * Transform hash for legal path. - * @return Hash - */ - private String safeHash() { - return this.hash.replaceAll("[* ]", "_"); - } + void save(String program, String ext, Scalar content) + throws IOException; } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java new file mode 100644 index 0000000000..db0a2c711d --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java @@ -0,0 +1,126 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import com.jcabi.log.Logger; +import java.io.IOException; +import java.nio.file.Path; +import org.cactoos.Scalar; +import org.cactoos.scalar.IoChecked; +import org.cactoos.text.IoCheckedText; +import org.cactoos.text.TextOf; + +/** + * Program footprint of EO compilation process. + *

The footprint consists of file in {@link #main} folder and optionally cached + * file in {@link #cache} folder. + * Caching is applied if {@link #hash} is not empty otherwise caching is ignored. + *

Usage example: + * + *

+ *    final Footprint footprint = new Footprint(
+ *      hash,
+ *      targetRoot,
+ *      cacheRoot
+ *    ).save(program, ext);
+ *
+ *    String content = footprint.content(program, ext);
+ *  
+ * + * @since 1.0 + */ +public final class FtCached implements Footprint { + /** + * Path to target root. + */ + private final Path main; + + /** + * Version tag. + */ + private final String hash; + + /** + * Path to cache root. + */ + private final Path cache; + + /** + * Ctor. + * @param hash Version tag + * @param main Main root + * @param cache Cache root + */ + public FtCached(final String hash, final Path main, final Path cache) { + this.hash = hash; + this.main = main; + this.cache = cache; + } + + @Override + public String load(final String program, final String ext) throws IOException { + final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext); + final Path target = new Place(program).make(this.main, ext); + final IoCheckedText content; + if (cached.toFile().exists()) { + content = new IoCheckedText( + new TextOf(cached) + ); + } else { + content = new IoCheckedText( + new TextOf(target) + ); + } + return content.asString(); + } + + @Override + public void save(final String program, final String ext, final Scalar content) + throws IOException { + final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext); + final Path target = new Place(program).make(this.main, ext); + final String text; + if (cached.toFile().exists()) { + Logger.info( + this, + "Program %s found in cache: %s", + program, + cached + ); + text = this.load(program, ext); + } else { + text = new IoChecked<>(content).value(); + new Save(text, cached).save(); + } + new Save(text, target).save(); + } + + /** + * Transform hash for legal path. + * @return Hash + */ + private String safeHash() { + return this.hash.replaceAll("[* ]", "_"); + } +} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/FtDefault.java b/eo-maven-plugin/src/main/java/org/eolang/maven/FtDefault.java new file mode 100644 index 0000000000..13579687a9 --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/FtDefault.java @@ -0,0 +1,69 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import java.io.IOException; +import java.nio.file.Path; +import org.cactoos.Scalar; +import org.cactoos.scalar.IoChecked; +import org.cactoos.text.IoCheckedText; +import org.cactoos.text.TextOf; + +/** + * Default implementation of a Footprint. + * @since 1.0 + */ +public final class FtDefault implements Footprint { + + /** + * Path to main location. + */ + private final Path main; + + /** + * Ctor. + * @param main Main location. + */ + public FtDefault(final Path main) { + this.main = main; + } + + @Override + public String load(final String program, final String ext) throws IOException { + return new IoCheckedText( + new TextOf( + new Place(program).make(this.main, ext) + ) + ).asString(); + } + + @Override + public void save(final String program, final String ext, final Scalar content) + throws IOException { + new Save( + new IoChecked<>(content).value(), + new Place(program).make(this.main, ext) + ).save(); + } +} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index 749ec577bd..b71fd0b976 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -128,17 +128,18 @@ public void exec() throws IOException { private void parse(final Tojo tojo) throws IOException { final Path source = Paths.get(tojo.get(AssembleMojo.ATTR_EO)); final String name = tojo.get(Tojos.KEY); - final String hash; + final Footprint footprint; if (tojo.exists(AssembleMojo.ATTR_HASH)) { - hash = tojo.get(AssembleMojo.ATTR_HASH); + footprint = new FtCached( + tojo.get(AssembleMojo.ATTR_HASH), + this.targetDir.toPath().resolve(ParseMojo.DIR), + this.parsedCache + ); } else { - hash = ""; + footprint = new FtDefault( + this.targetDir.toPath().resolve(ParseMojo.DIR) + ); } - final Footprint footprint = new Footprint( - hash, - this.targetDir.toPath().resolve(ParseMojo.DIR), - this.parsedCache - ); try { footprint.save( name, diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FtCachedTest.java similarity index 65% rename from eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java rename to eo-maven-plugin/src/test/java/org/eolang/maven/FtCachedTest.java index a2ef1451d0..49b1e1294b 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/FootprintTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FtCachedTest.java @@ -28,14 +28,12 @@ import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; /** * Tests for Cached. * @since 1.0 */ -final class FootprintTest { +final class FtCachedTest { @Test void testContentOfCachedFile(@TempDir final Path temp) throws Exception { final String content = String.join( @@ -44,28 +42,10 @@ void testContentOfCachedFile(@TempDir final Path temp) throws Exception { "", "" ); - new Footprint("abcde123", temp.resolve("target"), temp.resolve("parsed")) + new FtCached("abcde123", temp.resolve("target"), temp.resolve("parsed")) .save("org.eolang.txt.text", "xmir", () -> content); MatcherAssert.assertThat( - new Footprint("abcde123", temp.resolve("target"), temp.resolve("parsed")) - .load("org.eolang.txt.text", "xmir"), - Matchers.equalTo(content) - ); - } - - @ValueSource(strings = {"", " "}) - @ParameterizedTest - void testContentOfNoCacheFile(final String ver, @TempDir final Path temp) throws Exception { - final String content = String.join( - "\n", - "", - "", - "" - ); - new Footprint(ver, temp.resolve("target"), temp.resolve("parsed")) - .save("org.eolang.txt.text", "xmir", () -> content); - MatcherAssert.assertThat( - new Footprint("", temp.resolve("target"), temp.resolve("parsed")) + new FtCached("abcde123", temp.resolve("target"), temp.resolve("parsed")) .load("org.eolang.txt.text", "xmir"), Matchers.equalTo(content) ); diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/FtDefaultTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/FtDefaultTest.java new file mode 100644 index 0000000000..dd4624050d --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/FtDefaultTest.java @@ -0,0 +1,53 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2022 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.eolang.maven; + +import java.nio.file.Path; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +/** + * Tests for Cached. + * @since 1.0 + */ +final class FtDefaultTest { + @Test + void testContentOfNoCacheFile(@TempDir final Path temp) throws Exception { + final String content = String.join( + "\n", + "", + "", + "" + ); + new FtDefault(temp.resolve("target")) + .save("org.eolang.txt.text", "xmir", () -> content); + MatcherAssert.assertThat( + new FtDefault(temp.resolve("target")) + .load("org.eolang.txt.text", "xmir"), + Matchers.equalTo(content) + ); + } +} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index f4df38617b..4978051189 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -89,7 +89,7 @@ void testSimpleParsingCached(@TempDir final Path temp) throws Exception { src ).save(); final Path foreign = temp.resolve("eo-foreign.json"); - new Footprint( + new FtCached( new HashOfTag("0.25.0").narrow(), target, temp.resolve("parsed") From a4ccb8d905ac8b107a1a49e1d3cb9ae961d7e36f Mon Sep 17 00:00:00 2001 From: graur Date: Tue, 13 Sep 2022 14:33:22 +0300 Subject: [PATCH 32/39] #1212 - fixed linter checks for EOmemory.java --- eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java index dcd05fd824..3dd1381727 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOmemory.java @@ -73,7 +73,7 @@ private final class Write extends PhDefault { new AtComposite( this, rho -> { - Phi phi = new Data.ToPhi( + final Phi phi = new Data.ToPhi( new Dataized( rho.attr("x").get() ).take() From ae5f042159326857a4ae5e5eb9c8fc84d35df576 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Wed, 14 Sep 2022 10:04:44 +0300 Subject: [PATCH 33/39] logs --- .gitignore | 3 ++- eo-maven-plugin/src/main/java/org/eolang/maven/GmiMojo.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 65cde293ff..a932836017 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ target/ -.idea +.vscode/ +.idea/ .DS_Store *.iml .project diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/GmiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/GmiMojo.java index b3a6f1e7c2..fd4f293491 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/GmiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/GmiMojo.java @@ -330,6 +330,7 @@ private int render(final Path xmir, final Path gmi) throws IOException { .pass(after) .xpath("/text/text()") .get(0); + Logger.debug(this, "GMIs:\n%s", instructions); new Save(instructions, gmi).save(); if (this.generateGmiXmlFiles) { new Save( @@ -378,8 +379,11 @@ private void makeGraph(final String xembly, final Path gmi) throws IOException { gmi.resolveSibling(String.format("%s.graph", gmi.getFileName())) ).save(); if (this.generateDotFiles) { + final String dot = new Xsline(GmiMojo.TO_DOT) + .pass(graph).xpath("//dot/text()").get(0); + Logger.debug(this, "Dot:\n%s", dot); new Save( - new Xsline(GmiMojo.TO_DOT).pass(graph).xpath("//dot/text()").get(0), + dot, gmi.resolveSibling(String.format("%s.dot", gmi.getFileName())) ).save(); } From 8717d8238a04d377ff9f9d07dd50fbda2b6249f0 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Wed, 14 Sep 2022 10:28:39 +0300 Subject: [PATCH 34/39] better encapsulation --- .../java/org/eolang/parser/ParsingTrain.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java b/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java index 3dc0114f6d..9dd36485a7 100644 --- a/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java +++ b/eo-parser/src/main/java/org/eolang/parser/ParsingTrain.java @@ -27,15 +27,14 @@ import com.jcabi.xml.XSL; import com.jcabi.xml.XSLDocument; import com.yegor256.xsline.StAfter; -import com.yegor256.xsline.StClasspath; import com.yegor256.xsline.StLambda; import com.yegor256.xsline.TrBulk; +import com.yegor256.xsline.TrClasspath; import com.yegor256.xsline.TrDefault; import com.yegor256.xsline.TrEnvelope; import com.yegor256.xsline.TrFast; import com.yegor256.xsline.TrLambda; import com.yegor256.xsline.TrLogged; -import org.cactoos.iterable.Mapped; /** * Train of XSL shifts. @@ -89,22 +88,30 @@ public final class ParsingTrain extends TrEnvelope { /** * Ctor. */ + @SuppressWarnings("unchecked") public ParsingTrain() { super( new TrBulk<>( - new TrLambda( - new TrFast(new TrLogged(new TrDefault<>())), - shift -> new StAfter( - shift, - new StLambda( - shift::uid, - (pos, xml) -> ParsingTrain.EACH.with("step", pos) - .with("sheet", shift.uid()) - .transform(xml) + new TrClasspath<>( + new TrLambda( + new TrFast( + new TrLogged( + new TrDefault<>() + ) + ), + shift -> new StAfter( + shift, + new StLambda( + shift::uid, + (pos, xml) -> ParsingTrain.EACH.with("step", pos) + .with("sheet", shift.uid()) + .transform(xml) + ) ) - ) + ), + ParsingTrain.SHEETS ) - ).with(new Mapped<>(StClasspath::new, ParsingTrain.SHEETS)).back() + ).back().back() ); } From d89454c5988e2191afc68578dfedd74c4f9b7f94 Mon Sep 17 00:00:00 2001 From: graur Date: Wed, 14 Sep 2022 14:48:31 +0300 Subject: [PATCH 35/39] #1214 - solved the problem of parsing with copying an object with a method --- .../src/main/antlr4/org/eolang/parser/Program.g4 | 1 + .../src/main/java/org/eolang/parser/XeListener.java | 3 +++ .../org/eolang/parser/packs/syntax/copy.yaml | 12 ++++++++++++ eo-runtime/src/test/eo/org/eolang/runtime-tests.eo | 8 ++++++++ 4 files changed, 24 insertions(+) create mode 100644 eo-parser/src/test/resources/org/eolang/parser/packs/syntax/copy.yaml diff --git a/eo-parser/src/main/antlr4/org/eolang/parser/Program.g4 b/eo-parser/src/main/antlr4/org/eolang/parser/Program.g4 index 4886abe084..025bc0db7e 100644 --- a/eo-parser/src/main/antlr4/org/eolang/parser/Program.g4 +++ b/eo-parser/src/main/antlr4/org/eolang/parser/Program.g4 @@ -105,6 +105,7 @@ method | VERTEX ) + COPY? ; scope diff --git a/eo-parser/src/main/java/org/eolang/parser/XeListener.java b/eo-parser/src/main/java/org/eolang/parser/XeListener.java index d43a72d03e..cb13177878 100644 --- a/eo-parser/src/main/java/org/eolang/parser/XeListener.java +++ b/eo-parser/src/main/java/org/eolang/parser/XeListener.java @@ -269,6 +269,9 @@ public void enterMethod(final ProgramParser.MethodContext ctx) { ctx.getStart().getLine(), ctx.getStart().getCharPositionInLine() ); + if (ctx.COPY() != null) { + this.objects.prop("copy", ""); + } this.objects.prop("method", ""); this.objects.prop("base", String.format(".%s", ctx.mtd.getText())); this.objects.leave(); diff --git a/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/copy.yaml b/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/copy.yaml new file mode 100644 index 0000000000..852b5613f3 --- /dev/null +++ b/eo-parser/src/test/resources/org/eolang/parser/packs/syntax/copy.yaml @@ -0,0 +1,12 @@ +xsls: [] +tests: + - //objects[count(o)=1] + - //objects[count(.//o[@copy=''])=1] +eo: | + [] > test + [] > book + "qwerty" > title + book.title' > copy-title + eq. > @ + copy-title + "qwerty" diff --git a/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo b/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo index 6fb8bd84b2..bc076264ca 100644 --- a/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo +++ b/eo-runtime/src/test/eo/org/eolang/runtime-tests.eo @@ -343,3 +343,11 @@ assert-that b1.v $.equal-to 1 + +[] > copy-object-with-dot + [] > book + "qwerty" > title + book.title' > copy-title + eq. > @ + copy-title + "qwerty" From 1c40b2b4d9f3a8d75b673ec52df60d33002eacd7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 17:47:41 +0000 Subject: [PATCH 36/39] Update dependency org.slf4j:jul-to-slf4j to v2.0.1 --- eo-runtime/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/pom.xml b/eo-runtime/pom.xml index 2f87ebf0ee..ad25009fc9 100644 --- a/eo-runtime/pom.xml +++ b/eo-runtime/pom.xml @@ -41,7 +41,7 @@ SOFTWARE. org.slf4j jul-to-slf4j - 2.0.0 + 2.0.1 test From ea3fdd6722e025939aff220abd33a199e4acf775 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 14 Sep 2022 21:15:16 +0000 Subject: [PATCH 37/39] Update dependency org.slf4j:slf4j-reload4j to v2.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8c8e11d86f..e03e43b86d 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ SOFTWARE. org.slf4j slf4j-reload4j - 2.0.0 + 2.0.1 log4j From c5a5b9e4849cabb337b748f9f7e8f65defc3393b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 15 Sep 2022 03:20:38 +0000 Subject: [PATCH 38/39] Update dependency ch.qos.logback:logback-classic to v1.4.1 --- eo-runtime/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-runtime/pom.xml b/eo-runtime/pom.xml index 2f87ebf0ee..127378102f 100644 --- a/eo-runtime/pom.xml +++ b/eo-runtime/pom.xml @@ -53,7 +53,7 @@ SOFTWARE. ch.qos.logback logback-classic - 1.4.0 + 1.4.1 test From 64f603ce05d9229ae82abb4fe7bc192c714ef0ae Mon Sep 17 00:00:00 2001 From: mximp Date: Thu, 15 Sep 2022 11:16:08 +0300 Subject: [PATCH 39/39] #1062 make parsed cache non-configurable --- .../main/java/org/eolang/maven/AssembleMojo.java | 4 ++-- .../src/main/java/org/eolang/maven/FtCached.java | 12 ++---------- .../src/main/java/org/eolang/maven/ParseMojo.java | 13 +++++++++---- .../java/org/eolang/maven/AssembleMojoTest.java | 4 ++-- .../src/test/java/org/eolang/maven/GmiMojoTest.java | 2 +- .../java/org/eolang/maven/OptimizeMojoTest.java | 8 ++++---- .../test/java/org/eolang/maven/ParseMojoTest.java | 10 +++++----- .../test/java/org/eolang/maven/ResolveMojoTest.java | 6 +++--- .../java/org/eolang/maven/TranspileMojoTest.java | 8 ++++---- 9 files changed, 32 insertions(+), 35 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java index 5a5aaf0aab..93071f99bc 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java @@ -179,9 +179,9 @@ public final class AssembleMojo extends SafeMojo { * Parsed cache directory. * @checkstyle MemberNameCheck (7 lines) */ - @Parameter(property = "eo.parsed.cache") + @Parameter(property = "eo.cache") @SuppressWarnings("PMD.ImmutableField") - private Path parsedCache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed"); + private Path cache = Paths.get(System.getProperty("user.home")).resolve(".eo"); @Override public void exec() throws IOException { diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java index db0a2c711d..07a26ed7b3 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/FtCached.java @@ -80,7 +80,7 @@ public FtCached(final String hash, final Path main, final Path cache) { @Override public String load(final String program, final String ext) throws IOException { - final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext); + final Path cached = new Place(program).make(this.cache.resolve(this.hash), ext); final Path target = new Place(program).make(this.main, ext); final IoCheckedText content; if (cached.toFile().exists()) { @@ -98,7 +98,7 @@ public String load(final String program, final String ext) throws IOException { @Override public void save(final String program, final String ext, final Scalar content) throws IOException { - final Path cached = new Place(program).make(this.cache.resolve(this.safeHash()), ext); + final Path cached = new Place(program).make(this.cache.resolve(this.hash), ext); final Path target = new Place(program).make(this.main, ext); final String text; if (cached.toFile().exists()) { @@ -115,12 +115,4 @@ public void save(final String program, final String ext, final Scalar co } new Save(text, target).save(); } - - /** - * Transform hash for legal path. - * @return Hash - */ - private String safeHash() { - return this.hash.replaceAll("[* ]", "_"); - } } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java index b71fd0b976..c5f68cee11 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java @@ -68,12 +68,17 @@ public final class ParseMojo extends SafeMojo { public static final String DIR = "01-parse"; /** - * Parsed cache directory. + * Subdirectory for parsed cache. + */ + public static final String PARSED = "parsed"; + + /** + * EO cache directory. * @checkstyle MemberNameCheck (7 lines) */ - @Parameter(property = "eo.parsed.cache") + @Parameter(property = "eo.cache") @SuppressWarnings("PMD.ImmutableField") - private Path parsedCache = Paths.get(System.getProperty("user.home")).resolve(".eo/parsed"); + private Path cache = Paths.get(System.getProperty("user.home")).resolve(".eo"); /** * Whether we should fail on parsing error. @@ -133,7 +138,7 @@ private void parse(final Tojo tojo) throws IOException { footprint = new FtCached( tojo.get(AssembleMojo.ATTR_HASH), this.targetDir.toPath().resolve(ParseMojo.DIR), - this.parsedCache + this.cache.resolve(ParseMojo.PARSED) ); } else { footprint = new FtDefault( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java index 1c8cabe5ec..a275744e76 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoTest.java @@ -64,7 +64,7 @@ void assemblesTogether(@TempDir final Path temp) throws Exception { .with("foreign", temp.resolve("eo-foreign.json").toFile()) .with("foreignFormat", "json") .with("placed", temp.resolve("list").toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("skipZeroVersions", true) .with( "objectionary", @@ -122,7 +122,7 @@ void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws Except .with("foreign", temp.resolve("eo-foreign.json").toFile()) .with("foreignFormat", "json") .with("placed", temp.resolve("list").toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("skipZeroVersions", true) .with("failOnError", false) .with( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java index ea01402e37..ab70ba76e3 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/GmiMojoTest.java @@ -140,7 +140,7 @@ private static String toXembly(final String code) throws IOException { new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute(); new Moja<>(OptimizeMojo.class) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java index 7b7831d7f9..9885fac7bd 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java @@ -57,7 +57,7 @@ void skipsAlreadyOptimized(@TempDir final Path temp) throws Exception { new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute(); new Moja<>(OptimizeMojo.class) @@ -97,7 +97,7 @@ void optimizesIfExpired(@TempDir final Path temp) throws Exception { .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) .with("foreignFormat", "csv") - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .execute(); new Moja<>(OptimizeMojo.class) .with("targetDir", target.toFile()) @@ -138,7 +138,7 @@ void testSimpleOptimize(@TempDir final Path temp) throws Exception { .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) .with("foreignFormat", "csv") - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .execute(); new Moja<>(OptimizeMojo.class) .with("targetDir", target.toFile()) @@ -187,7 +187,7 @@ void testOptimizeWithFailOnErrorFlag(@TempDir final Path temp) throws Exception .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) .with("foreignFormat", "csv") - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .execute(); new Moja<>(OptimizeMojo.class) .with("targetDir", target.toFile()) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java index 4978051189..49cc1ccea8 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java @@ -61,7 +61,7 @@ void testSimpleParsing(@TempDir final Path temp) throws Exception { new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute(); MatcherAssert.assertThat( @@ -109,7 +109,7 @@ void testSimpleParsingCached(@TempDir final Path temp) throws Exception { .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) .with("foreignFormat", "csv") - .with("parsedCache", temp.resolve("parsed")) + .with("cache", temp.resolve("parsed")) .execute(); MatcherAssert.assertThat( Files.exists( @@ -142,7 +142,7 @@ void testCrashOnInvalidSyntax(@TempDir final Path temp) () -> new Moja<>(ParseMojo.class) .with("targetDir", temp.resolve("target").toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute() ); @@ -163,7 +163,7 @@ void testCrashesWithFileName(@TempDir final Path temp) () -> new Moja<>(ParseMojo.class) .with("targetDir", temp.resolve("target").toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute() ); @@ -188,7 +188,7 @@ void testDoNotCrashesWithFailOnError(@TempDir final Path temp) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) .with("foreignFormat", "csv") - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("failOnError", false) .execute(); MatcherAssert.assertThat( diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java index 327bf8be97..92937fcb4f 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java @@ -53,7 +53,7 @@ void testSimpleResolve(@TempDir final Path temp) throws Exception { new Moja<>(ParseMojo.class) .with("foreign", foreign.toFile()) .with("targetDir", target.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .execute(); new Moja<>(OptimizeMojo.class) .with("targetDir", target.toFile()) @@ -110,7 +110,7 @@ void testConflictingDependencies(@TempDir final Path temp) throws IOException { new Moja<>(ParseMojo.class) .with("foreign", foreign.toFile()) .with("targetDir", target.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .execute(); new Moja<>(OptimizeMojo.class) .with("targetDir", target.toFile()) @@ -170,7 +170,7 @@ void testConflictingDependenciesNoFail(@TempDir final Path temp) throws IOExcept new Moja<>(ParseMojo.class) .with("foreign", foreign.toFile()) .with("targetDir", target.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .execute(); new Moja<>(OptimizeMojo.class) .with("targetDir", target.toFile()) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java index 0dcc138684..bcb81297a3 100755 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoTest.java @@ -72,7 +72,7 @@ void recompilesIfExpired(@TempDir final Path temp) new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute(); new Moja<>(OptimizeMojo.class) @@ -126,7 +126,7 @@ void testFailOnWarning(@TempDir final Path temp) throws Exception { new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute(); new Moja<>(OptimizeMojo.class) @@ -175,7 +175,7 @@ void testFailOnError(@TempDir final Path temp) throws Exception { new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .with("failOnError", false) .execute(); @@ -262,7 +262,7 @@ private Path compileToFile( new Moja<>(ParseMojo.class) .with("targetDir", target.toFile()) .with("foreign", foreign.toFile()) - .with("parsedCache", temp.resolve("cache/parsed")) + .with("cache", temp.resolve("cache/parsed")) .with("foreignFormat", "csv") .execute(); new Moja<>(OptimizeMojo.class)