From b0bc12f544b9734669d6f7f2d971a6c668d20776 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 05:12:25 +0300 Subject: [PATCH 01/14] add unphi tests --- .../org/eolang/maven/UnphiMojoCacheTest.java | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java new file mode 100644 index 0000000000..8e0cd2a00c --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java @@ -0,0 +1,100 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2024 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.yegor256.Mktmp; +import com.yegor256.MktmpResolver; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.eolang.maven.util.HmBase; +import org.eolang.maven.util.Home; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.ExpectedToFail; + +/** + * Test cases for caching in {@link UnphiMojo}. + * @since 0.50.0 + */ +@ExtendWith(MktmpResolver.class) +@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass") +final class UnphiMojoCacheTest { + + @Test + @ExpectedToFail + void touchesCacheNot(@Mktmp final Path temp) throws Exception { + final Home workspace = new HmBase(temp); + workspace.save( + "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", + Paths.get("target/eo/phi/std.phi") + ); + workspace.save( + "some valid XMIR", + Paths.get("target/eo/1-parse/std.xmir") + ); + final File xmir = temp.resolve("target/1-parse/std.xmir").toFile(); + final long modified = xmir.lastModified(); + new FakeMaven(temp).execute(UnphiMojo.class); + MatcherAssert.assertThat( + String.format( + "There should be file with .%s extension after parsing phi to XMIR, but there isn't", + AssembleMojo.XMIR + ), + modified, + Matchers.equalTo(xmir.lastModified()) + ); + } + + @Test + void touchesInvalidCache(@Mktmp final Path temp) throws Exception { + final Home workspace = new HmBase(temp); + workspace.save( + "some valid XMIR", + Paths.get("target/eo/1-parse/std.xmir") + ); + workspace.save( + "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", + Paths.get("target/eo/phi/std.phi") + ); + final File xmir = temp.resolve("target/1-parse/std.xmir").toFile(); + final long modified = xmir.lastModified(); + final FakeMaven mvn = new FakeMaven(temp).execute(UnphiMojo.class); + workspace.save( + "some valid XMIR", + Paths.get("target/1-parse/std.xmir") + ); + mvn.execute(UnphiMojo.class); + MatcherAssert.assertThat( + String.format( + "There should be file with .%s extension after parsing phi to XMIR, but there isn't", + AssembleMojo.XMIR + ), + modified, + Matchers.lessThan(xmir.lastModified()) + ); + } +} From b8477c937da714ea50b33f9cd3357572c4190dd9 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 06:15:21 +0300 Subject: [PATCH 02/14] fixed tests --- .../org/eolang/maven/UnphiMojoCacheTest.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java index 8e0cd2a00c..6dda67af32 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java @@ -25,7 +25,9 @@ import com.yegor256.Mktmp; import com.yegor256.MktmpResolver; +import com.yegor256.farea.Farea; import java.io.File; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import org.eolang.maven.util.HmBase; @@ -53,17 +55,14 @@ void touchesCacheNot(@Mktmp final Path temp) throws Exception { Paths.get("target/eo/phi/std.phi") ); workspace.save( - "some valid XMIR", + "some valid XMIR after unphi", Paths.get("target/eo/1-parse/std.xmir") ); - final File xmir = temp.resolve("target/1-parse/std.xmir").toFile(); + final File xmir = temp.resolve("target/eo/1-parse/std.xmir").toFile(); final long modified = xmir.lastModified(); - new FakeMaven(temp).execute(UnphiMojo.class); + this.executePhiToXmir(new Farea(temp)); MatcherAssert.assertThat( - String.format( - "There should be file with .%s extension after parsing phi to XMIR, but there isn't", - AssembleMojo.XMIR - ), + "XMIR file recreated twice", modified, Matchers.equalTo(xmir.lastModified()) ); @@ -73,28 +72,33 @@ void touchesCacheNot(@Mktmp final Path temp) throws Exception { void touchesInvalidCache(@Mktmp final Path temp) throws Exception { final Home workspace = new HmBase(temp); workspace.save( - "some valid XMIR", + "some valid XMIR that appeared before phi", Paths.get("target/eo/1-parse/std.xmir") ); workspace.save( "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", Paths.get("target/eo/phi/std.phi") ); - final File xmir = temp.resolve("target/1-parse/std.xmir").toFile(); + final File xmir = temp.resolve("target/eo/1-parse/std.xmir").toFile(); final long modified = xmir.lastModified(); - final FakeMaven mvn = new FakeMaven(temp).execute(UnphiMojo.class); - workspace.save( - "some valid XMIR", - Paths.get("target/1-parse/std.xmir") - ); - mvn.execute(UnphiMojo.class); + this.executePhiToXmir(new Farea(temp)); MatcherAssert.assertThat( - String.format( - "There should be file with .%s extension after parsing phi to XMIR, but there isn't", - AssembleMojo.XMIR - ), + "phi-to-xmir cache not invalidated", modified, Matchers.lessThan(xmir.lastModified()) ); } + + private void executePhiToXmir(final Farea farea) throws IOException { + farea.together( + f -> { + f.build() + .plugins() + .appendItself() + .execution() + .goals("phi-to-xmir"); + f.exec("compile"); + } + ); + } } From f44b42a3c0928c081f539af600f6f7c0e9712fcf Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 5 Jan 2025 02:35:02 +0300 Subject: [PATCH 03/14] add phi-to-xmir CACHE dir constant, change tests --- .../main/java/org/eolang/maven/UnphiMojo.java | 6 ++ .../org/eolang/maven/UnphiMojoCacheTest.java | 66 +++++++++++++------ 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index 20dc3d168c..d206eae6cf 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -62,6 +62,12 @@ threadSafe = true ) public final class UnphiMojo extends SafeMojo { + + /** + * Subdirectory for parsed cache. + */ + static final String CACHE = "unphied"; + /** * Unphi transformations. */ diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java index 6dda67af32..48d53126c9 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2016-2024 Objectionary.com + * Copyright (c) 2016-2025 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 @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ + package org.eolang.maven; import com.yegor256.Mktmp; @@ -28,8 +29,12 @@ import com.yegor256.farea.Farea; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import org.cactoos.text.TextOf; +import org.eolang.maven.footprint.FpDefault; import org.eolang.maven.util.HmBase; import org.eolang.maven.util.Home; import org.hamcrest.MatcherAssert; @@ -48,44 +53,63 @@ final class UnphiMojoCacheTest { @Test @ExpectedToFail - void touchesCacheNot(@Mktmp final Path temp) throws Exception { + void usesCache(@Mktmp final Path temp) throws Exception { final Home workspace = new HmBase(temp); + final Path phi = Paths.get("target/eo/phi/std.phi"); + final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); workspace.save( "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", - Paths.get("target/eo/phi/std.phi") - ); - workspace.save( - "some valid XMIR after unphi", - Paths.get("target/eo/1-parse/std.xmir") + phi ); - final File xmir = temp.resolve("target/eo/1-parse/std.xmir").toFile(); - final long modified = xmir.lastModified(); + final String cache = "some valid phi cache"; + new FpDefault( + src -> cache, + temp.resolve("cache").resolve(UnphiMojo.CACHE), + "version-1.0", + "123ZaRiFcHiK321", + Path.of("std.xmir") + ).apply(temp.resolve(phi), temp.resolve(xmir)); this.executePhiToXmir(new Farea(temp)); MatcherAssert.assertThat( "XMIR file recreated twice", - modified, - Matchers.equalTo(xmir.lastModified()) + new TextOf(workspace.load(xmir)), + Matchers.equalTo(cache) ); } @Test - void touchesInvalidCache(@Mktmp final Path temp) throws Exception { + @ExpectedToFail + void invalidatesCache(@Mktmp final Path temp) throws Exception { final Home workspace = new HmBase(temp); - workspace.save( - "some valid XMIR that appeared before phi", - Paths.get("target/eo/1-parse/std.xmir") - ); + final Path phi = Paths.get("target/eo/phi/std.phi"); + final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); + final Path cache = Path.of("cache") + .resolve(UnphiMojo.CACHE) + .resolve("version-1.0") + .resolve("123ZaRiFcHiK321") + .resolve("std.xmir"); workspace.save( "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", - Paths.get("target/eo/phi/std.phi") + phi + ); + new FpDefault( + src -> "some valid phi cache", + temp.resolve("cache").resolve(UnphiMojo.CACHE), + "version-1.0", + "123ZaRiFcHiK321", + Path.of("std.xmir") + ).apply(temp.resolve(phi), temp.resolve(xmir)); + Files.setLastModifiedTime( + temp.resolve(phi), + FileTime.fromMillis(System.currentTimeMillis() + 50_000) ); - final File xmir = temp.resolve("target/eo/1-parse/std.xmir").toFile(); - final long modified = xmir.lastModified(); + final File cached = temp.resolve(cache).toFile(); + final long old = cached.lastModified(); this.executePhiToXmir(new Farea(temp)); MatcherAssert.assertThat( "phi-to-xmir cache not invalidated", - modified, - Matchers.lessThan(xmir.lastModified()) + old, + Matchers.lessThan(cached.lastModified()) ); } From 7fd21fae9ad0f45c35c9d35ac3d6f16914709135 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 5 Jan 2025 08:42:32 +0300 Subject: [PATCH 04/14] fix typo --- .../src/test/java/org/eolang/maven/UnphiMojoCacheTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java index 48d53126c9..623140d1a4 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java @@ -61,7 +61,7 @@ void usesCache(@Mktmp final Path temp) throws Exception { "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", phi ); - final String cache = "some valid phi cache"; + final String cache = "some valid XMIR from cache"; new FpDefault( src -> cache, temp.resolve("cache").resolve(UnphiMojo.CACHE), @@ -93,7 +93,7 @@ void invalidatesCache(@Mktmp final Path temp) throws Exception { phi ); new FpDefault( - src -> "some valid phi cache", + src -> "some valid XMIR from cache", temp.resolve("cache").resolve(UnphiMojo.CACHE), "version-1.0", "123ZaRiFcHiK321", From 9f9eab4f8c34bb7a1f65c9179d3eb655302930cb Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 04:48:59 +0300 Subject: [PATCH 05/14] disable UnphiMojo cache tests, move tests to UnphiMojoTest --- .../org/eolang/maven/UnphiMojoCacheTest.java | 128 ------------------ .../java/org/eolang/maven/UnphiMojoTest.java | 81 +++++++++++ 2 files changed, 81 insertions(+), 128 deletions(-) delete mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java deleted file mode 100644 index 623140d1a4..0000000000 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoCacheTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2025 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.yegor256.Mktmp; -import com.yegor256.MktmpResolver; -import com.yegor256.farea.Farea; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.attribute.FileTime; -import org.cactoos.text.TextOf; -import org.eolang.maven.footprint.FpDefault; -import org.eolang.maven.util.HmBase; -import org.eolang.maven.util.Home; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junitpioneer.jupiter.ExpectedToFail; - -/** - * Test cases for caching in {@link UnphiMojo}. - * @since 0.50.0 - */ -@ExtendWith(MktmpResolver.class) -@SuppressWarnings("JTCOP.RuleAllTestsHaveProductionClass") -final class UnphiMojoCacheTest { - - @Test - @ExpectedToFail - void usesCache(@Mktmp final Path temp) throws Exception { - final Home workspace = new HmBase(temp); - final Path phi = Paths.get("target/eo/phi/std.phi"); - final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); - workspace.save( - "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", - phi - ); - final String cache = "some valid XMIR from cache"; - new FpDefault( - src -> cache, - temp.resolve("cache").resolve(UnphiMojo.CACHE), - "version-1.0", - "123ZaRiFcHiK321", - Path.of("std.xmir") - ).apply(temp.resolve(phi), temp.resolve(xmir)); - this.executePhiToXmir(new Farea(temp)); - MatcherAssert.assertThat( - "XMIR file recreated twice", - new TextOf(workspace.load(xmir)), - Matchers.equalTo(cache) - ); - } - - @Test - @ExpectedToFail - void invalidatesCache(@Mktmp final Path temp) throws Exception { - final Home workspace = new HmBase(temp); - final Path phi = Paths.get("target/eo/phi/std.phi"); - final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); - final Path cache = Path.of("cache") - .resolve(UnphiMojo.CACHE) - .resolve("version-1.0") - .resolve("123ZaRiFcHiK321") - .resolve("std.xmir"); - workspace.save( - "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", - phi - ); - new FpDefault( - src -> "some valid XMIR from cache", - temp.resolve("cache").resolve(UnphiMojo.CACHE), - "version-1.0", - "123ZaRiFcHiK321", - Path.of("std.xmir") - ).apply(temp.resolve(phi), temp.resolve(xmir)); - Files.setLastModifiedTime( - temp.resolve(phi), - FileTime.fromMillis(System.currentTimeMillis() + 50_000) - ); - final File cached = temp.resolve(cache).toFile(); - final long old = cached.lastModified(); - this.executePhiToXmir(new Farea(temp)); - MatcherAssert.assertThat( - "phi-to-xmir cache not invalidated", - old, - Matchers.lessThan(cached.lastModified()) - ); - } - - private void executePhiToXmir(final Farea farea) throws IOException { - farea.together( - f -> { - f.build() - .plugins() - .appendItself() - .execution() - .goals("phi-to-xmir"); - f.exec("compile"); - } - ); - } -} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index 882778d897..7a55bb2f33 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -31,11 +31,13 @@ import com.yegor256.MktmpResolver; import com.yegor256.WeAreOnline; import com.yegor256.farea.Farea; +import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -44,7 +46,9 @@ import org.cactoos.set.SetOf; import org.cactoos.text.TextOf; import org.eolang.jucs.ClasspathSource; +import org.eolang.maven.footprint.FpDefault; import org.eolang.maven.util.HmBase; +import org.eolang.maven.util.Home; import org.eolang.parser.EoSyntax; import org.eolang.parser.StrictXmir; import org.eolang.xax.XtSticky; @@ -54,6 +58,7 @@ import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -63,6 +68,7 @@ * Test cases for {@link UnphiMojo}. * @since 0.34.0 */ +@SuppressWarnings("PMD.TooManyMethods") @ExtendWith(MktmpResolver.class) final class UnphiMojoTest { @@ -296,4 +302,79 @@ void convertsValidXmirAndParsableEO(final boolean reversed, @Mktmp final Path te XhtmlMatchers.hasXPath("/program[not(errors)]") ); } + + @Test + @Disabled + void usesCache(@Mktmp final Path temp) throws Exception { + final Home workspace = new HmBase(temp); + final Path phi = Paths.get("target/eo/phi/std.phi"); + final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); + workspace.save( + "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", + phi + ); + final String cache = "some valid XMIR from cache"; + new FpDefault( + src -> cache, + temp.resolve("cache").resolve(UnphiMojo.CACHE), + "version-1.0", + "123ZaRiFcHiK321", + Path.of("std.xmir") + ).apply(temp.resolve(phi), temp.resolve(xmir)); + this.executePhiToXmir(new Farea(temp)); + MatcherAssert.assertThat( + "XMIR file recreated twice", + new TextOf(workspace.load(xmir)), + Matchers.equalTo(cache) + ); + } + + @Test + @Disabled + void invalidatesCache(@Mktmp final Path temp) throws Exception { + final Home workspace = new HmBase(temp); + final Path phi = Paths.get("target/eo/phi/std.phi"); + final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); + final Path cache = Path.of("cache") + .resolve(UnphiMojo.CACHE) + .resolve("version-1.0") + .resolve("123ZaRiFcHiK321") + .resolve("std.xmir"); + workspace.save( + "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", + phi + ); + new FpDefault( + src -> "some valid XMIR from cache", + temp.resolve("cache").resolve(UnphiMojo.CACHE), + "version-1.0", + "123ZaRiFcHiK321", + Path.of("std.xmir") + ).apply(temp.resolve(phi), temp.resolve(xmir)); + Files.setLastModifiedTime( + temp.resolve(phi), + FileTime.fromMillis(System.currentTimeMillis() + 50_000) + ); + final File cached = temp.resolve(cache).toFile(); + final long old = cached.lastModified(); + this.executePhiToXmir(new Farea(temp)); + MatcherAssert.assertThat( + "phi-to-xmir cache not invalidated", + old, + Matchers.lessThan(cached.lastModified()) + ); + } + + private void executePhiToXmir(final Farea farea) throws IOException { + farea.together( + f -> { + f.build() + .plugins() + .appendItself() + .execution() + .goals("phi-to-xmir"); + f.exec("compile"); + } + ); + } } From 9c3f8796e5e00c0401e6a0b773dc348e11ad12d6 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 05:01:09 +0300 Subject: [PATCH 06/14] add todo: enable tests --- .../src/test/java/org/eolang/maven/UnphiMojoTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index 7a55bb2f33..bf1b3538c2 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -67,6 +67,9 @@ /** * Test cases for {@link UnphiMojo}. * @since 0.34.0 + * @todo #3708:30min Remove @Disabled + * {@code UnphiMojoTest.usesCache()} and {@code UnphiMojoTest.invalidatesCache()} + * when cache is implemented, fix tests if needed. */ @SuppressWarnings("PMD.TooManyMethods") @ExtendWith(MktmpResolver.class) From ae7881991cfdca218b2570ddd9e0c0281dc7e05c Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 06:51:37 +0300 Subject: [PATCH 07/14] moved from Farea to FkMaven, get rid of Saved --- .../java/org/eolang/maven/UnphiMojoTest.java | 107 ++++++++---------- 1 file changed, 48 insertions(+), 59 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index bf1b3538c2..df87f4287a 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -37,7 +37,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.attribute.FileTime; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -46,9 +45,9 @@ import org.cactoos.set.SetOf; import org.cactoos.text.TextOf; import org.eolang.jucs.ClasspathSource; -import org.eolang.maven.footprint.FpDefault; +import org.eolang.maven.footprint.CachePath; +import org.eolang.maven.footprint.Saved; import org.eolang.maven.util.HmBase; -import org.eolang.maven.util.Home; import org.eolang.parser.EoSyntax; import org.eolang.parser.StrictXmir; import org.eolang.xax.XtSticky; @@ -309,75 +308,65 @@ void convertsValidXmirAndParsableEO(final boolean reversed, @Mktmp final Path te @Test @Disabled void usesCache(@Mktmp final Path temp) throws Exception { - final Home workspace = new HmBase(temp); - final Path phi = Paths.get("target/eo/phi/std.phi"); - final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); - workspace.save( + new Saved( "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", - phi - ); - final String cache = "some valid XMIR from cache"; - new FpDefault( - src -> cache, - temp.resolve("cache").resolve(UnphiMojo.CACHE), - "version-1.0", - "123ZaRiFcHiK321", - Path.of("std.xmir") - ).apply(temp.resolve(phi), temp.resolve(xmir)); - this.executePhiToXmir(new Farea(temp)); + temp.resolve("target/eo/phi/std.phi") + ).value(); + final String hash = "123ZaRiFcHiK321"; + final Path cache = temp.resolve("cache"); + final String expected = "some valid XMIR from cache"; + new Saved( + expected, + new CachePath( + cache.resolve(UnphiMojo.CACHE), + FakeMaven.pluginVersion(), + hash, + Path.of("std.xmir") + ).get() + ).value(); + new FakeMaven(temp) + .with("cache", cache.toFile()) + .with("unphiInputDir", temp.resolve("target/eo/phi/").toFile()) + .with("unphiOutputDir", temp.resolve("target/eo/1-parse").toFile()) + .allTojosWithHash(() -> hash) + .execute(UnphiMojo.class); MatcherAssert.assertThat( - "XMIR file recreated twice", - new TextOf(workspace.load(xmir)), - Matchers.equalTo(cache) + "XMIR file is not loaded from cache", + new TextOf(Files.readString(temp.resolve("target/eo/1-parse/std.xmir"))), + Matchers.equalTo(expected) ); } @Test @Disabled void invalidatesCache(@Mktmp final Path temp) throws Exception { - final Home workspace = new HmBase(temp); - final Path phi = Paths.get("target/eo/phi/std.phi"); - final Path xmir = Paths.get("target/eo/1-parse/std.xmir"); - final Path cache = Path.of("cache") - .resolve(UnphiMojo.CACHE) - .resolve("version-1.0") - .resolve("123ZaRiFcHiK321") - .resolve("std.xmir"); - workspace.save( + final String hash = "123ZaRiFcHiK321"; + final Path cache = temp.resolve("cache"); + final File cached = new Saved( + "some invalid (old) XMIR from cache", + new CachePath( + cache.resolve(UnphiMojo.CACHE), + FakeMaven.pluginVersion(), + hash, + Path.of("std.xmir") + ).get() + ).value() + .toFile(); + new Saved( "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", - phi - ); - new FpDefault( - src -> "some valid XMIR from cache", - temp.resolve("cache").resolve(UnphiMojo.CACHE), - "version-1.0", - "123ZaRiFcHiK321", - Path.of("std.xmir") - ).apply(temp.resolve(phi), temp.resolve(xmir)); - Files.setLastModifiedTime( - temp.resolve(phi), - FileTime.fromMillis(System.currentTimeMillis() + 50_000) - ); - final File cached = temp.resolve(cache).toFile(); + temp.resolve("target/eo/phi/std.phi") + ).value(); final long old = cached.lastModified(); - this.executePhiToXmir(new Farea(temp)); + new FakeMaven(temp) + .with("cache", cache.toFile()) + .with("unphiInputDir", temp.resolve("target/eo/phi/").toFile()) + .with("unphiOutputDir", temp.resolve("target/eo/1-parse").toFile()) + .allTojosWithHash(() -> hash) + .execute(UnphiMojo.class); MatcherAssert.assertThat( - "phi-to-xmir cache not invalidated", + "XMIR cache not invalidated", old, Matchers.lessThan(cached.lastModified()) ); } - - private void executePhiToXmir(final Farea farea) throws IOException { - farea.together( - f -> { - f.build() - .plugins() - .appendItself() - .execution() - .goals("phi-to-xmir"); - f.exec("compile"); - } - ); - } } From dda7c74defd16eeaeb6e34d7049ddfc09f2567f8 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 07:23:53 +0300 Subject: [PATCH 08/14] add UnphiMojo cache implementation todo --- .../src/main/java/org/eolang/maven/UnphiMojo.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index d206eae6cf..f997ced1a3 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -55,6 +55,15 @@ /** * Read PHI files and parse them to the XMIR. * @since 0.34.0 + * @todo #3708:60min implement cache. + * I assume that files received from dir via Walk should be synced with tojos: + * 1) File is not present in tojos -> + * add file to tojos with column PHI equals Path of the file. + * 2) File is present in tojos and not unphied + * (XMIR is younger that PHI or XMIR doesn't exist or PHI doesn't exist) -> + * add column PHI equals Path of the file if not exists. + * When all files are synced we should pass all not unphied tojos to the + * {@code FpDefault} reusing existing unPhi logic */ @Mojo( name = "phi-to-xmir", From 466751153b0aeb33fd98ed6fe3ead1b53ca7f357 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 07:29:37 +0300 Subject: [PATCH 09/14] fix 0pdd check --- .../src/test/java/org/eolang/maven/UnphiMojoTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index df87f4287a..bfecc25fa9 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -66,9 +66,9 @@ /** * Test cases for {@link UnphiMojo}. * @since 0.34.0 - * @todo #3708:30min Remove @Disabled + * @todo #3708:30min Remove @Disabled annotation on * {@code UnphiMojoTest.usesCache()} and {@code UnphiMojoTest.invalidatesCache()} - * when cache is implemented, fix tests if needed. + * when cache is implemented, check that tests is valid otherwise fix them if needed. */ @SuppressWarnings("PMD.TooManyMethods") @ExtendWith(MktmpResolver.class) From 4f5a845f8f9faf14c150106a694cac20f6194127 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 08:37:11 +0300 Subject: [PATCH 10/14] retrieve std.xmir from FakeMaven --- .../java/org/eolang/maven/UnphiMojoTest.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index bfecc25fa9..4cb04a5c9f 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -324,15 +324,18 @@ void usesCache(@Mktmp final Path temp) throws Exception { Path.of("std.xmir") ).get() ).value(); - new FakeMaven(temp) - .with("cache", cache.toFile()) - .with("unphiInputDir", temp.resolve("target/eo/phi/").toFile()) - .with("unphiOutputDir", temp.resolve("target/eo/1-parse").toFile()) - .allTojosWithHash(() -> hash) - .execute(UnphiMojo.class); MatcherAssert.assertThat( "XMIR file is not loaded from cache", - new TextOf(Files.readString(temp.resolve("target/eo/1-parse/std.xmir"))), + new TextOf( + new FakeMaven(temp) + .with("cache", cache.toFile()) + .with("unphiInputDir", temp.resolve("target/eo/phi/").toFile()) + .with("unphiOutputDir", temp.resolve("target/eo/1-parse").toFile()) + .allTojosWithHash(() -> hash) + .execute(UnphiMojo.class) + .result() + .get("target/eo/1-parse/std.xmir") + ), Matchers.equalTo(expected) ); } From bc5a27a5093341905a85c859e860d7d8be40bdf9 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Wed, 8 Jan 2025 09:06:55 +0300 Subject: [PATCH 11/14] fixed typo in todo --- eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index f997ced1a3..45d84de67b 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -60,7 +60,7 @@ * 1) File is not present in tojos -> * add file to tojos with column PHI equals Path of the file. * 2) File is present in tojos and not unphied - * (XMIR is younger that PHI or XMIR doesn't exist or PHI doesn't exist) -> + * (PHI is younger than XMIR or XMIR doesn't exist or PHI doesn't exist) -> * add column PHI equals Path of the file if not exists. * When all files are synced we should pass all not unphied tojos to the * {@code FpDefault} reusing existing unPhi logic From 78d011388ff4f3425bbe8d7985f3ea900fad04d5 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Fri, 10 Jan 2025 07:43:21 +0300 Subject: [PATCH 12/14] remove todo --- .../src/main/java/org/eolang/maven/UnphiMojo.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index 45d84de67b..d206eae6cf 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -55,15 +55,6 @@ /** * Read PHI files and parse them to the XMIR. * @since 0.34.0 - * @todo #3708:60min implement cache. - * I assume that files received from dir via Walk should be synced with tojos: - * 1) File is not present in tojos -> - * add file to tojos with column PHI equals Path of the file. - * 2) File is present in tojos and not unphied - * (PHI is younger than XMIR or XMIR doesn't exist or PHI doesn't exist) -> - * add column PHI equals Path of the file if not exists. - * When all files are synced we should pass all not unphied tojos to the - * {@code FpDefault} reusing existing unPhi logic */ @Mojo( name = "phi-to-xmir", From 53f27dde7b0b57c88026fed2749a0caf8e3a5723 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Fri, 10 Jan 2025 07:45:41 +0300 Subject: [PATCH 13/14] compare TextOf via asString, formatting fix --- .../src/test/java/org/eolang/maven/UnphiMojoTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index 4cb04a5c9f..2fd73f5b97 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -335,7 +335,7 @@ void usesCache(@Mktmp final Path temp) throws Exception { .execute(UnphiMojo.class) .result() .get("target/eo/1-parse/std.xmir") - ), + ).asString(), Matchers.equalTo(expected) ); } @@ -353,8 +353,7 @@ void invalidatesCache(@Mktmp final Path temp) throws Exception { hash, Path.of("std.xmir") ).get() - ).value() - .toFile(); + ).value().toFile(); new Saved( "{⟦std ↦ Φ.org.eolang.io.stdout, y ↦ Φ.org.eolang.x⟧}", temp.resolve("target/eo/phi/std.phi") From d5e211168c540e0371cb1de9912d56c52644bcd8 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Fri, 10 Jan 2025 17:02:55 +0300 Subject: [PATCH 14/14] remove unused CACHE constant --- .../src/main/java/org/eolang/maven/UnphiMojo.java | 5 ----- .../src/test/java/org/eolang/maven/UnphiMojoTest.java | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java index d206eae6cf..1c2d32a74b 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/UnphiMojo.java @@ -63,11 +63,6 @@ ) public final class UnphiMojo extends SafeMojo { - /** - * Subdirectory for parsed cache. - */ - static final String CACHE = "unphied"; - /** * Unphi transformations. */ diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java index 2fd73f5b97..c3a19abc7b 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnphiMojoTest.java @@ -318,7 +318,7 @@ void usesCache(@Mktmp final Path temp) throws Exception { new Saved( expected, new CachePath( - cache.resolve(UnphiMojo.CACHE), + cache.resolve("unphied"), FakeMaven.pluginVersion(), hash, Path.of("std.xmir") @@ -348,7 +348,7 @@ void invalidatesCache(@Mktmp final Path temp) throws Exception { final File cached = new Saved( "some invalid (old) XMIR from cache", new CachePath( - cache.resolve(UnphiMojo.CACHE), + cache.resolve("unphied"), FakeMaven.pluginVersion(), hash, Path.of("std.xmir")