From f0bc901b702e75a0fa22bc04050983b98001cc4d Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 05:24:31 +0300 Subject: [PATCH 1/9] add support for different extensions in Unplace --- .../main/java/org/eolang/maven/Unplace.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java index d96cf8fac89..34eb9fb45cb 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java @@ -38,6 +38,11 @@ final class Unplace { */ private final Path parent; + /** + * The file extension. + */ + private final String extension; + /** * Ctor. * @param dir The name of the parent dir @@ -51,7 +56,26 @@ final class Unplace { * @param dir The name of the parent dir */ Unplace(final Path dir) { + this(dir, ".eo$"); + } + + /** + * Ctor. + * @param dir The name of the parent dir + * @param extension The file extension + */ + Unplace(final File dir, final String extension) { + this(dir.toPath(), extension); + } + + /** + * Main Ctor. + * @param dir The name of the parent dir + * @param extension The file extension + */ + Unplace(final Path dir, final String extension) { this.parent = dir; + this.extension = extension; } /** @@ -62,7 +86,7 @@ final class Unplace { public String make(final Path file) { return file.toString().substring( this.parent.toString().length() + 1 - ).replaceAll(".eo$", "").replace(File.separator, "."); + ).replaceAll(this.extension, "").replace(File.separator, "."); } } From 65fb3fddea1d38e5aaf844c9a451b4890e884a86 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 05:25:36 +0300 Subject: [PATCH 2/9] add PHI attribute --- .../src/main/java/org/eolang/maven/tojos/ForeignTojos.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java index 516bf8cb80d..984a9c3504f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojos.java @@ -374,7 +374,12 @@ enum Attribute { /** * Git SHA of the object in the {@code objectionary/home}. */ - HASH("hash"); + HASH("hash"), + + /** + * Absolute path of the parsed from XMIR to phi-expression file. + */ + PHI("phi"); /** * Attribute name. From 2b4aad83b730ba6f912a746aa74ca722319e78c4 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 05:27:37 +0300 Subject: [PATCH 3/9] add methods needed for synchronising missing files with tojos and invalidating PhiMojo/UnphiMojo caches --- .../org/eolang/maven/tojos/ForeignTojo.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java index 328c0ea28a0..650fdf24e43 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java @@ -125,6 +125,14 @@ public String description() { ); } + /** + * The tojo phi. + * @return The phi. + */ + public Path phi() { + return Paths.get(this.attribute(ForeignTojos.Attribute.PHI)); + } + /** * The tojo hash. * @return The hash. @@ -204,6 +212,46 @@ public boolean notParsed() { return res; } + /** + * Check if the given tojo has not been parsed to phi-expression. + * + * @return True if the tojo has not been parsed to phi-expression. + */ + public boolean notPhied() { + boolean res = true; + if (this.delegate.exists(ForeignTojos.Attribute.PHI.getKey())) { + final Path phi = this.phi(); + if (phi.toFile().lastModified() >= this.optimized().toFile().lastModified()) { + Logger.debug( + this, "Already executed xmir-to-phi: %s to %[file]s (it's newer than the XMIR)", + this.identifier(), phi + ); + res = false; + } + } + return res; + } + + /** + * Check if the given tojo has not been parsed to XMIR from phi-expression. + * + * @return True if the tojo has not been parsed from XMIR to phi-expression. + */ + public boolean notUnphied() { + boolean res = true; + if (this.delegate.exists(ForeignTojos.Attribute.XMIR.getKey())) { + final Path xmir = this.xmir(); + if (xmir.toFile().lastModified() >= this.phi().toFile().lastModified()) { + Logger.debug( + this, "Already executed phi-to-xmir: %s to %[file]s (it's newer than the phi)", + this.identifier(), xmir + ); + res = false; + } + } + return res; + } + /** * Checks if tojo has hash. * @return True if has hash, false otherwise. @@ -345,6 +393,16 @@ public ForeignTojo withScope(final String scope) { return this; } + /** + * Set the phi. + * @param phi The phi. + * @return The tojo itself. + */ + public ForeignTojo withPhi(final Path phi) { + this.delegate.set(ForeignTojos.Attribute.PHI.getKey(), phi); + return this; + } + /** * Return the scope of the tojo. * @return The scope. From a814a3fa8bc4f9dcbcb4fc31650835e708da8c47 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 06:27:13 +0300 Subject: [PATCH 4/9] update readme --- eo-maven-plugin/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eo-maven-plugin/README.md b/eo-maven-plugin/README.md index 659bc3da0ed..0a83bc6fba2 100644 --- a/eo-maven-plugin/README.md +++ b/eo-maven-plugin/README.md @@ -85,9 +85,9 @@ one after another: It's done by the `org.eolang.parser.EoSyntax` class in the `eo-parser` module. It takes 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. + The output of the parser you can find in the `target/eo/1-parse` directory. Parsed objects which are versioned (normally pulled from - [Objectionary](https://github.com/objectionary/home)) are cached in `.eo/parsed` folder. + [Objectionary](https://github.com/objectionary/home)) are cached in `.eo/1-parsed` folder. * **Optimization**. There are a number of [XSL transformations](https://en.wikipedia.org/wiki/XSLT) @@ -97,7 +97,7 @@ one after another: The class `org.eolang.parser.Program` is responsible for making XSLT transformations and the entire list of them is stored in the `org.eolang.parser.Pack` class. Some of XLST files are sanity checks (or linters). - The output of each transformation you can find in the `target/eo/optimize` directory. + The output of each transformation you can find in the `target/eo/2-optimize` directory. * **Compilation**. The class `org.eolang.maven.TranspileMojo` in the `eo-maven-plugin` module is responsible From 886775da9245aa47c3e9239260335dd42852d459 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Sun, 29 Dec 2024 06:46:24 +0300 Subject: [PATCH 5/9] fix codacity --- eo-maven-plugin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/README.md b/eo-maven-plugin/README.md index 0a83bc6fba2..df1695dcd37 100644 --- a/eo-maven-plugin/README.md +++ b/eo-maven-plugin/README.md @@ -87,7 +87,7 @@ one after another: using [ANTLR4](https://www.antlr.org/) and [Xembly](https://www.xembly.org). The output of the parser you can find in the `target/eo/1-parse` directory. Parsed objects which are versioned (normally pulled from - [Objectionary](https://github.com/objectionary/home)) are cached in `.eo/1-parsed` folder. + [Objectionary](https://github.com/objectionary/home)) are cached in `.eo/1-parse` folder. * **Optimization**. There are a number of [XSL transformations](https://en.wikipedia.org/wiki/XSLT) From 81c9aab0aaa6b5621c9f625c5c74cfb4388679e6 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 30 Dec 2024 14:49:51 +0300 Subject: [PATCH 6/9] fix readme typo --- eo-maven-plugin/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/README.md b/eo-maven-plugin/README.md index df1695dcd37..491bfdbceff 100644 --- a/eo-maven-plugin/README.md +++ b/eo-maven-plugin/README.md @@ -87,7 +87,7 @@ one after another: using [ANTLR4](https://www.antlr.org/) and [Xembly](https://www.xembly.org). The output of the parser you can find in the `target/eo/1-parse` directory. Parsed objects which are versioned (normally pulled from - [Objectionary](https://github.com/objectionary/home)) are cached in `.eo/1-parse` folder. + [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 63050048d5001b6faae25decc5ee518909b09b29 Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 30 Dec 2024 15:10:17 +0300 Subject: [PATCH 7/9] add required checks to notPhi notUnphi --- .../src/main/java/org/eolang/maven/tojos/ForeignTojo.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java index 650fdf24e43..d369cd69e56 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java @@ -219,7 +219,8 @@ public boolean notParsed() { */ public boolean notPhied() { boolean res = true; - if (this.delegate.exists(ForeignTojos.Attribute.PHI.getKey())) { + if (this.delegate.exists(ForeignTojos.Attribute.PHI.getKey()) + && this.delegate.exists(ForeignTojos.Attribute.OPTIMIZED.getKey())) { final Path phi = this.phi(); if (phi.toFile().lastModified() >= this.optimized().toFile().lastModified()) { Logger.debug( @@ -239,7 +240,8 @@ public boolean notPhied() { */ public boolean notUnphied() { boolean res = true; - if (this.delegate.exists(ForeignTojos.Attribute.XMIR.getKey())) { + if (this.delegate.exists(ForeignTojos.Attribute.XMIR.getKey()) + && this.delegate.exists(ForeignTojos.Attribute.PHI.getKey())) { final Path xmir = this.xmir(); if (xmir.toFile().lastModified() >= this.phi().toFile().lastModified()) { Logger.debug( From c00b9b60fe61999f50b79c34459dc4203b99b56c Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 30 Dec 2024 15:10:55 +0300 Subject: [PATCH 8/9] add add pattern.quote, add tests --- .../main/java/org/eolang/maven/Unplace.java | 8 +++-- .../java/org/eolang/maven/UnplaceTest.java | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java b/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java index 34eb9fb45cb..e7443aa0520 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java @@ -25,6 +25,7 @@ import java.io.File; import java.nio.file.Path; +import java.util.regex.Pattern; /** * Make program name from a path. @@ -56,7 +57,7 @@ final class Unplace { * @param dir The name of the parent dir */ Unplace(final Path dir) { - this(dir, ".eo$"); + this(dir, ".eo"); } /** @@ -86,7 +87,10 @@ final class Unplace { public String make(final Path file) { return file.toString().substring( this.parent.toString().length() + 1 - ).replaceAll(this.extension, "").replace(File.separator, "."); + ).replaceAll( + Pattern.quote(this.extension).concat("$"), + "" + ).replace(File.separator, "."); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceTest.java index 63698b7f261..6185a0110e2 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceTest.java @@ -26,6 +26,8 @@ import java.nio.file.Paths; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; @@ -55,4 +57,31 @@ void makesName( ); } + @ParameterizedTest + @CsvSource({ + "/tmp/foo/bar, /tmp/foo/bar/a/b/c.phi, a.b.c", + "/tmp/foo/bar, /tmp/foo/bar/a/b/.cd.ef.phi, a.b..cd.ef" + }) + void makesNameWithCustomExtension( + final String base, + final String source, + final String name + ) { + MatcherAssert.assertThat( + CatalogsTest.TO_ADD_MESSAGE, + new Unplace(Paths.get(base), ".phi").make( + Paths.get(source) + ), + Matchers.equalTo(name) + ); + } + + @Test + void interpretsExtensionAsLiteralString() { + Assertions.assertDoesNotThrow( + () -> new Unplace(Paths.get("/tmp/foo/bar"), "(") + .make(Paths.get("/tmp/foo/bar/a/b/c(")), + "Extension interpreted not as literal string" + ); + } } From 470df80993594c5b910beb6f8e040496befe2a4a Mon Sep 17 00:00:00 2001 From: Artem Getmanskii Date: Mon, 30 Dec 2024 15:35:28 +0300 Subject: [PATCH 9/9] use XMIR instead of OPTIMIZED --- eo-maven-plugin/README.md | 4 ++-- .../src/main/java/org/eolang/maven/tojos/ForeignTojo.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eo-maven-plugin/README.md b/eo-maven-plugin/README.md index 491bfdbceff..659bc3da0ed 100644 --- a/eo-maven-plugin/README.md +++ b/eo-maven-plugin/README.md @@ -85,7 +85,7 @@ one after another: It's done by the `org.eolang.parser.EoSyntax` class in the `eo-parser` module. It takes 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/1-parse` directory. + 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. @@ -97,7 +97,7 @@ one after another: The class `org.eolang.parser.Program` is responsible for making XSLT transformations and the entire list of them is stored in the `org.eolang.parser.Pack` class. Some of XLST files are sanity checks (or linters). - The output of each transformation you can find in the `target/eo/2-optimize` directory. + The output of each transformation you can find in the `target/eo/optimize` directory. * **Compilation**. The class `org.eolang.maven.TranspileMojo` in the `eo-maven-plugin` module is responsible diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java index a05ddb9ce96..99b0954771c 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/tojos/ForeignTojo.java @@ -194,9 +194,9 @@ public boolean notParsed() { public boolean notPhied() { boolean res = true; if (this.delegate.exists(ForeignTojos.Attribute.PHI.getKey()) - && this.delegate.exists(ForeignTojos.Attribute.OPTIMIZED.getKey())) { + && this.delegate.exists(ForeignTojos.Attribute.XMIR.getKey())) { final Path phi = this.phi(); - if (phi.toFile().lastModified() >= this.optimized().toFile().lastModified()) { + if (phi.toFile().lastModified() >= this.xmir().toFile().lastModified()) { Logger.debug( this, "Already executed xmir-to-phi: %s to %[file]s (it's newer than the XMIR)", this.identifier(), phi