From ea4d5e6da4d34c642f1d55351bc4bfface90846a Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:03:56 +0300 Subject: [PATCH 01/14] #2678 remove failOnError from AssembleMojo --- .../java/org/eolang/maven/AssembleMojo.java | 14 ------------- .../org/eolang/maven/AssembleMojoTest.java | 20 ++++++------------- 2 files changed, 6 insertions(+), 28 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 e6639c62dd..cb7681a86f 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 @@ -164,20 +164,6 @@ public final class AssembleMojo extends SafeMojo { @SuppressWarnings("PMD.LongVariable") private boolean ignoreVersionConflicts; - /** - * Whether we should fail on error. - * @checkstyle MemberNameCheck (11 lines) - * @since 0.23.0 - * @todo #2443:90min Remove the following failOnError flag. Now we - * have already got rid from it in {@link OptimizeMojo} and {@link VerifyMojo}. - * We need to make failOnError the behaviour default. - */ - @SuppressWarnings("PMD.ImmutableField") - @Parameter( - property = "eo.failOnError", - defaultValue = "true") - private boolean failOnError = true; - /** * Whether we should fail on warn. * @checkstyle MemberNameCheck (10 lines) 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 be34d72d36..c9b253b59d 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 @@ -215,20 +215,12 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { } @Test - void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws IOException { - final Map result = new FakeMaven(temp) - .withProgram(AssembleMojoTest.INVALID_PROGRAM) - .with("failOnError", false) - .execute(AssembleMojo.class).result(); - MatcherAssert.assertThat( - "Even if the eo program invalid we still have to parse it, but we didn't", - result.get(String.format("target/%s", ParseMojo.DIR)), - new ContainsFiles(String.format("**/main.%s", TranspileMojo.EXT)) - ); - MatcherAssert.assertThat( - "Since the eo program invalid we shouldn't have optimized it, but we did", - result.get(String.format("target/%s", OptimizeMojo.DIR)), - Matchers.not(new ContainsFiles(String.format("**/main.%s", TranspileMojo.EXT))) + void assembleFailsOnError(@TempDir final Path temp) { + Assertions.assertThrows( + IllegalStateException.class, + () -> new FakeMaven(temp) + .withProgram(AssembleMojoTest.INVALID_PROGRAM) + .execute(new FakeMaven.Verify()) ); } From 96baa7d82a73160b71cd109b4ac5be2dd37daf4a Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:12:31 +0300 Subject: [PATCH 02/14] #2678 rename test --- .../src/test/java/org/eolang/maven/AssembleMojoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c9b253b59d..a858fb7d8e 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 @@ -215,7 +215,7 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { } @Test - void assembleFailsOnError(@TempDir final Path temp) { + void failsOnError(@TempDir final Path temp) { Assertions.assertThrows( IllegalStateException.class, () -> new FakeMaven(temp) From 5c63f38281f7552e317ce743e3de9cb55113fc6c Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 11 Dec 2023 16:16:11 +0300 Subject: [PATCH 03/14] #2683: iterating via factory map --- .../org/eolang/maven/BinarizeParseMojo.java | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index 26f360a4ad..91eec3fb2e 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -37,11 +37,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.List; +import java.util.Map; +import java.util.function.Function; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.cactoos.map.MapOf; import org.eolang.maven.rust.FFINode; import org.eolang.maven.rust.Names; import org.eolang.maven.rust.RustNode; @@ -110,6 +112,20 @@ public final class BinarizeParseMojo extends SafeMojo { */ private Names names; + /** + * Map that matches ffi insert xpath to building of FFINode. + */ + private final Map> factory = new MapOf<>( + "/program/rusts/rust", + (final XML node) -> new RustNode( + node, + this.names, + this.targetDir.toPath().resolve("Lib"), + this.eoPortalDir.toPath(), + this.generatedDir.toPath().resolve("EOrust").resolve("natives") + ) + ); + @Override public void exec() throws IOException { new File(this.targetDir.toPath().resolve("Lib/").toString()).mkdirs(); @@ -122,11 +138,13 @@ public void exec() throws IOException { } /** - * Creates a "rust" section in xml file and returns the resulting XML. + * Creates a ffi's sections in xml file and returns the resulting XML. + * For example, creates "/program/rusts" section with "rust" node inside. * @param input The .xmir file * @return The content of rust section + * @checkstyle AbbreviationAsWordInNameCheck (8 lines) */ - private XML addRust( + private XML injectFFIs( final XML input ) { final String name = input.xpath("/program/@name").get(0); @@ -142,26 +160,18 @@ private XML addRust( * Add ffi node via xsl transformation and return list of them. * @param input Input xmir. * @return FFI nodes. - * @todo #2609:90min We can make the current class more generic - * by transferring this.addRust(input) snippet to corresponding - * FFINode- {@link RustNode}. We wanna make the class independent of - * ffi-insert as a result. * @checkstyle AbbreviationAsWordInNameCheck (8 lines) */ private Collection getFFIs(final XML input) { - final List nodes = this.addRust(input).nodes("/program/rusts/rust"); - final Collection ret = new ArrayList<>(nodes.size()); - for (final XML node : nodes) { - ret.add( - new RustNode( - node, - this.names, - this.targetDir.toPath().resolve("Lib"), - this.eoPortalDir.toPath(), - this.generatedDir.toPath().resolve("EOrust").resolve("natives") - ) - ); - } + final Collection ret = new ArrayList<>(0); + final XML injected = this.injectFFIs(input); + this.factory.forEach( + (xpath, ctor) -> { + for (final XML node : injected.nodes(xpath)) { + ret.add(ctor.apply(node)); + } + } + ); return ret; } From f7cf37465628df18a94d1d3506f82084a9445fbd Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 11 Dec 2023 16:23:41 +0300 Subject: [PATCH 04/14] #2683: addFFIs --- .../src/main/java/org/eolang/maven/BinarizeParseMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index 97a76da363..2f69e45748 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -165,7 +165,7 @@ private XML addFFIs( */ private Collection getFFIs(final XML input) { final Collection ret = new ArrayList<>(0); - final XML injected = this.injectFFIs(input); + final XML injected = this.addFFIs(input); this.factory.forEach( (xpath, ctor) -> { for (final XML node : injected.nodes(xpath)) { From 2eb174f740e5106f2cee5d83706636043a98ac3a Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:14:26 +0300 Subject: [PATCH 05/14] #2678 remove failOnError from everywhere --- .../main/java/org/eolang/maven/ParseMojo.java | 27 +++++-------------- .../org/eolang/maven/AssembleMojoTest.java | 2 +- .../org/eolang/maven/DiscoverMojoTest.java | 1 - .../java/org/eolang/maven/ParseMojoTest.java | 15 ----------- .../java/org/eolang/maven/SafeMojoTest.java | 1 - 5 files changed, 8 insertions(+), 38 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 af19bdf09f..1c7e053d81 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 @@ -79,17 +79,6 @@ public final class ParseMojo extends SafeMojo { */ public static final String PARSED = "parsed"; - /** - * Whether we should fail on parsing error. - * @checkstyle MemberNameCheck (7 lines) - * @since 0.23.0 - */ - @SuppressWarnings("PMD.ImmutableField") - @Parameter( - property = "eo.failOnError", - defaultValue = "true") - private boolean failOnError = true; - /** * The current version of eo-maven-plugin. * Maven 3 only. @@ -190,18 +179,16 @@ private void parse(final ForeignTojo tojo) throws IOException { for (final XML error : errors) { Logger.error( this, - "Failed to parse '%s:%s': %s (just logging, because of failOnError=false)", + "Failed to parse '%s:%s': %s", source, error.xpath("@line").get(0), error.xpath("text()").get(0) ); } - if (this.failOnError) { - throw new IllegalArgumentException( - String.format( - "Failed to parse %s (%d parsing errors)", - source, errors.size() - ) - ); - } + throw new IllegalArgumentException( + String.format( + "Failed to parse %s (%d parsing errors)", + source, errors.size() + ) + ); } } } 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 a858fb7d8e..9980f4fb85 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 @@ -215,7 +215,7 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { } @Test - void failsOnError(@TempDir final Path temp) { + void failsOnInvalidProgram(@TempDir final Path temp) { Assertions.assertThrows( IllegalStateException.class, () -> new FakeMaven(temp) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/DiscoverMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/DiscoverMojoTest.java index 21e2255531..7c2fe189ee 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/DiscoverMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/DiscoverMojoTest.java @@ -213,7 +213,6 @@ void discoversDifferentUnversionedObjectsFromDifferentVersionedObjects(@TempDir void doesNotDiscoverWithVersions(@TempDir final Path tmp) throws IOException { final FakeMaven maven = new FakeMaven(tmp) .with("withVersions", false) - .with("failOnError", false) .withVersionedProgram() .execute(new FakeMaven.Discover()); final ObjectName seq = new OnVersioned("org.eolang.seq", "6c6269d"); 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 c154c3a033..e04c297693 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 @@ -122,27 +122,12 @@ void crashesOnInvalidSyntax(@TempDir final Path temp) { IllegalStateException.class, () -> new FakeMaven(temp) .withProgram("something > is wrong here") - .with("failOnError", true) .execute(ParseMojo.class) ).getCause().getCause().getMessage(), Matchers.containsString("Failed to parse") ); } - @Test - void doesNotCrashesWithFailOnError(@TempDir final Path temp) throws Exception { - MatcherAssert.assertThat( - new FakeMaven(temp) - .withProgram("something < is wrong here") - .with("failOnError", false) - .execute(new FakeMaven.Parse()) - .result(), - Matchers.hasKey( - String.format("target/%s/foo/x/main.%s", ParseMojo.DIR, TranspileMojo.EXT) - ) - ); - } - @Test void doesNotParseIfAlreadyParsed(@TempDir final Path temp) throws IOException { final FakeMaven maven = new FakeMaven(temp); diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java index 34dac747a7..4ffeea7381 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java @@ -46,7 +46,6 @@ void logsStackTrace(final Logs out, @TempDir final Path temp) { IllegalStateException.class, () -> new FakeMaven(temp) .withProgram("something > is definitely wrong here") - .with("failOnError", true) .execute(ParseMojo.class) ); MatcherAssert.assertThat( From 4d14009116ad5fa5706425a7e4dfe574e7f17676 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 11 Dec 2023 16:55:29 +0300 Subject: [PATCH 06/14] #2683: refactor --- .../org/eolang/maven/BinarizeParseMojo.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index 2f69e45748..b5265f5ad9 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Map; +import java.util.function.BiFunction; import java.util.function.Function; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -76,7 +77,7 @@ public final class BinarizeParseMojo extends SafeMojo { * the end of the xmir file. When adding a new language for FFI inserts, you need to add the * appropriate XSL transformation. */ - static final Train TRAIN = new TrBulk<>( + private static final Train TRAIN = new TrBulk<>( new TrClasspath<>( new ParsingTrain() .empty() @@ -86,6 +87,21 @@ public final class BinarizeParseMojo extends SafeMojo { ) ).back().back(); + /** + * Map that matches ffi insert xpath to building of FFINode. + */ + private static final Map> factory + = new MapOf<>( + "/program/rusts/rust", + (node, mojo) -> new RustNode( + node, + mojo.names, + mojo.targetDir.toPath().resolve("Lib"), + mojo.eoPortalDir.toPath(), + mojo.generatedDir.toPath().resolve("EOrust").resolve("natives") + ) + ); + /** * Target directory. * @checkstyle MemberNameCheck (7 lines) @@ -114,20 +130,6 @@ public final class BinarizeParseMojo extends SafeMojo { */ private Names names; - /** - * Map that matches ffi insert xpath to building of FFINode. - */ - private final Map> factory = new MapOf<>( - "/program/rusts/rust", - (final XML node) -> new RustNode( - node, - this.names, - this.targetDir.toPath().resolve("Lib"), - this.eoPortalDir.toPath(), - this.generatedDir.toPath().resolve("EOrust").resolve("natives") - ) - ); - @Override public void exec() throws IOException { new File(this.targetDir.toPath().resolve("Lib/").toString()).mkdirs(); @@ -166,12 +168,11 @@ private XML addFFIs( private Collection getFFIs(final XML input) { final Collection ret = new ArrayList<>(0); final XML injected = this.addFFIs(input); - this.factory.forEach( - (xpath, ctor) -> { - for (final XML node : injected.nodes(xpath)) { - ret.add(ctor.apply(node)); - } - } + + BinarizeParseMojo.factory.forEach( + (xpath, ctor) -> injected + .nodes(xpath) + .forEach(node -> ret.add(ctor.apply(node, this))) ); return ret; } From 95a8c7ddb684cbeefbf95bf7f72823ad5a9d3a66 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 11 Dec 2023 16:56:07 +0300 Subject: [PATCH 07/14] #2683: refactor --- .../src/main/java/org/eolang/maven/BinarizeParseMojo.java | 1 - 1 file changed, 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index b5265f5ad9..efd456fc4f 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -39,7 +39,6 @@ import java.util.Collection; import java.util.Map; import java.util.function.BiFunction; -import java.util.function.Function; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; From 00085485895de1c8a07979609ad7c51f15ff4552 Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 11 Dec 2023 17:07:51 +0300 Subject: [PATCH 08/14] #2683: refactored again --- .../src/main/java/org/eolang/maven/BinarizeParseMojo.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index efd456fc4f..f5ade8fe0d 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -89,8 +89,8 @@ public final class BinarizeParseMojo extends SafeMojo { /** * Map that matches ffi insert xpath to building of FFINode. */ - private static final Map> factory - = new MapOf<>( + private static final + Map> FACTORY = new MapOf<>( "/program/rusts/rust", (node, mojo) -> new RustNode( node, @@ -167,8 +167,7 @@ private XML addFFIs( private Collection getFFIs(final XML input) { final Collection ret = new ArrayList<>(0); final XML injected = this.addFFIs(input); - - BinarizeParseMojo.factory.forEach( + BinarizeParseMojo.FACTORY.forEach( (xpath, ctor) -> injected .nodes(xpath) .forEach(node -> ret.add(ctor.apply(node, this))) From c0a1fad01ec9a3a87992579b2460ff8f321b9b2f Mon Sep 17 00:00:00 2001 From: levBagryansky <28lev11@gmail.com> Date: Mon, 11 Dec 2023 17:13:07 +0300 Subject: [PATCH 09/14] #2683: refactored again --- .../src/main/java/org/eolang/maven/BinarizeParseMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index f5ade8fe0d..bc05402caa 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java @@ -92,7 +92,7 @@ public final class BinarizeParseMojo extends SafeMojo { private static final Map> FACTORY = new MapOf<>( "/program/rusts/rust", - (node, mojo) -> new RustNode( + (node, mojo) -> new RustNode( node, mojo.names, mojo.targetDir.toPath().resolve("Lib"), From 5a0a34fd0af1d12ae5e3181bb158f711b26d67aa Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Mon, 11 Dec 2023 18:03:53 +0300 Subject: [PATCH 10/14] #2678 add assert message --- .../src/test/java/org/eolang/maven/AssembleMojoTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 9980f4fb85..749494f541 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 @@ -220,7 +220,8 @@ void failsOnInvalidProgram(@TempDir final Path temp) { IllegalStateException.class, () -> new FakeMaven(temp) .withProgram(AssembleMojoTest.INVALID_PROGRAM) - .execute(new FakeMaven.Verify()) + .execute(new FakeMaven.Verify()), + "Invalid program with wrong syntax should have failed, but it didn't" ); } From 2dcaea6393381e7e36ef6be221deb32bede9a0e5 Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:57:37 +0300 Subject: [PATCH 11/14] #2678 remove exception from ParseMojo --- .../main/java/org/eolang/maven/OptimizeMojo.java | 3 +-- .../main/java/org/eolang/maven/ParseMojo.java | 16 +++++----------- .../main/java/org/eolang/maven/VerifyMojo.java | 8 ++++++-- .../java/org/eolang/maven/AssembleMojoTest.java | 12 ------------ .../java/org/eolang/maven/OptimizeMojoTest.java | 2 +- .../java/org/eolang/maven/ParseMojoTest.java | 14 ++++++-------- .../test/java/org/eolang/maven/SafeMojoTest.java | 2 +- 7 files changed, 20 insertions(+), 37 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java index 20f0129c7a..79a8fccb89 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java @@ -122,7 +122,7 @@ public void exec() throws IOException { * @return Optimization for all tojos. */ private Optimization optimization() { - Optimization opt; + final Optimization opt; if (this.trackOptimizationSteps) { opt = new OptSpy( new ParsingTrain(), @@ -131,7 +131,6 @@ private Optimization optimization() { } else { opt = new OptTrain(new ParsingTrain()); } - opt = new OptTrain(opt, "/org/eolang/parser/fail-on-critical.xsl"); return opt; } } 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 1c7e053d81..65d73d0cfe 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 @@ -165,12 +165,12 @@ private void parse(final ForeignTojo tojo) throws IOException { ); final XML xmir = new XMLDocument(footprint.load(name, "xmir")); final List errors = xmir.nodes("/program/errors/error"); + final Path target = new Place(name).make( + this.targetDir.toPath().resolve(ParseMojo.DIR), + TranspileMojo.EXT + ); + tojo.withXmir(target.toAbsolutePath()); if (errors.isEmpty()) { - final Path target = new Place(name).make( - this.targetDir.toPath().resolve(ParseMojo.DIR), - TranspileMojo.EXT - ); - tojo.withXmir(target.toAbsolutePath()); Logger.debug( this, "Parsed %s to %s", new Rel(source), new Rel(target) @@ -183,12 +183,6 @@ private void parse(final ForeignTojo tojo) throws IOException { source, error.xpath("@line").get(0), error.xpath("text()").get(0) ); } - throw new IllegalArgumentException( - String.format( - "Failed to parse %s (%d parsing errors)", - source, errors.size() - ) - ); } } } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java index d620bfde66..55d06bc251 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java @@ -24,6 +24,7 @@ package org.eolang.maven; import com.jcabi.log.Logger; +import com.yegor256.xsline.TrClasspath; import com.yegor256.xsline.TrDefault; import java.io.IOException; import java.nio.file.Path; @@ -103,8 +104,11 @@ void exec() throws IOException { */ private Optimization optimization() { Optimization opt = new OptTrain( - new OptTrain(new TrDefault<>()), - "/org/eolang/parser/fail-on-errors.xsl" + new TrClasspath<>( + new TrDefault<>(), + "/org/eolang/parser/fail-on-errors.xsl", + "/org/eolang/parser/fail-on-critical.xsl" + ).back() ); if (this.failOnWarning) { opt = new OptTrain(opt, "/org/eolang/parser/fail-on-warnings.xsl"); 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 749494f541..85a4bdd8df 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 @@ -225,18 +225,6 @@ void failsOnInvalidProgram(@TempDir final Path temp) { ); } - @Test - void doesNotAssembleIfFailOnErrorFlagIsTrue(@TempDir final Path temp) { - final Class expected = IllegalStateException.class; - Assertions.assertThrows( - expected, - () -> new FakeMaven(temp) - .withProgram(AssembleMojoTest.INVALID_PROGRAM) - .execute(AssembleMojo.class), - String.format("AssembleMojo should have failed with %s, but didn't", expected) - ); - } - @CaptureLogs @Test void assemblesSuccessfullyInOfflineMode(final Logs out, @TempDir final Path temp) { 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 82aab5f6d7..c8038e3234 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 @@ -230,7 +230,7 @@ void failsOnCritical(@TempDir final Path temp) throws IOException { " TRUE > x", " FALSE > x" ).with("trackOptimizationSteps", true) - .execute(new FakeMaven.Optimize()) + .execute(new FakeMaven.Verify()) ); } 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 e04c297693..1d06b5e58d 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 @@ -117,14 +117,12 @@ void parsesWithCache(@TempDir final Path temp) throws Exception { @Test void crashesOnInvalidSyntax(@TempDir final Path temp) { - MatcherAssert.assertThat( - Assertions.assertThrows( - IllegalStateException.class, - () -> new FakeMaven(temp) - .withProgram("something > is wrong here") - .execute(ParseMojo.class) - ).getCause().getCause().getMessage(), - Matchers.containsString("Failed to parse") + Assertions.assertThrows( + IllegalStateException.class, + () -> new FakeMaven(temp) + .withProgram("something > is wrong here") + .execute(new FakeMaven.Verify()), + "Program with invalid syntax should have failed, but it didn't" ); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java index 4ffeea7381..9c64468535 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java @@ -46,7 +46,7 @@ void logsStackTrace(final Logs out, @TempDir final Path temp) { IllegalStateException.class, () -> new FakeMaven(temp) .withProgram("something > is definitely wrong here") - .execute(ParseMojo.class) + .execute(new FakeMaven.Verify()) ); MatcherAssert.assertThat( String.join("\n", out.captured()), From d3811e7cfcae5d4b81ffe33ded5507623a79601e Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:33:46 +0300 Subject: [PATCH 12/14] #2678 move tests for fail to VerifyMojo --- .../org/eolang/maven/AssembleMojoTest.java | 23 +++++++---- .../org/eolang/maven/OptimizeMojoTest.java | 13 ++++--- .../java/org/eolang/maven/ParseMojoTest.java | 16 ++++---- .../java/org/eolang/maven/VerifyMojoTest.java | 38 +++++++++++++++++++ 4 files changed, 70 insertions(+), 20 deletions(-) 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 85a4bdd8df..9cad584cf3 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 @@ -74,7 +74,7 @@ final class AssembleMojoTest { /** * Invalid eo program for testing. */ - private static final String[] INVALID_PROGRAM = { + static final String[] INVALID_PROGRAM = { "+alias stdout org.eolang.io.stdout", "+home https://github.com/objectionary/eo", "+package test", @@ -215,13 +215,20 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { } @Test - void failsOnInvalidProgram(@TempDir final Path temp) { - Assertions.assertThrows( - IllegalStateException.class, - () -> new FakeMaven(temp) - .withProgram(AssembleMojoTest.INVALID_PROGRAM) - .execute(new FakeMaven.Verify()), - "Invalid program with wrong syntax should have failed, but it didn't" + void assemblesNotFailWithFailOnError(@TempDir final Path temp) throws IOException { + final Map result = new FakeMaven(temp) + .withProgram(AssembleMojoTest.INVALID_PROGRAM) + .execute(new FakeMaven.Optimize()) + .result(); + MatcherAssert.assertThat( + "Even if the eo program invalid we still have to parse it, but we didn't", + result.get(String.format("target/%s", ParseMojo.DIR)), + new ContainsFiles(String.format("**/main.%s", TranspileMojo.EXT)) + ); + MatcherAssert.assertThat( + "Even if the eo program invalid we still have to optimize it, but we didn't", + result.get(String.format("target/%s", OptimizeMojo.DIR)), + new ContainsFiles(String.format("**/main.%s", TranspileMojo.EXT)) ); } 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 c8038e3234..848a8cc4e3 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 @@ -219,10 +219,9 @@ void optimizesConcurrentlyWithLotsOfPrograms(@TempDir final Path temp) throws IO } @Test - void failsOnCritical(@TempDir final Path temp) throws IOException { - Assertions.assertThrows( - IllegalStateException.class, - () -> new FakeMaven(temp) + void doesNotCrashesOnError(@TempDir final Path temp) throws Exception { + MatcherAssert.assertThat( + new FakeMaven(temp) .withProgram( "+package f\n", "[args] > main", @@ -230,7 +229,11 @@ void failsOnCritical(@TempDir final Path temp) throws IOException { " TRUE > x", " FALSE > x" ).with("trackOptimizationSteps", true) - .execute(new FakeMaven.Verify()) + .execute(new FakeMaven.Optimize()) + .result(), + Matchers.hasKey( + String.format("target/%s/foo/x/main.%s", ParseMojo.DIR, TranspileMojo.EXT) + ) ); } 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 1d06b5e58d..99f9ff5496 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 @@ -116,13 +116,15 @@ void parsesWithCache(@TempDir final Path temp) throws Exception { } @Test - void crashesOnInvalidSyntax(@TempDir final Path temp) { - Assertions.assertThrows( - IllegalStateException.class, - () -> new FakeMaven(temp) - .withProgram("something > is wrong here") - .execute(new FakeMaven.Verify()), - "Program with invalid syntax should have failed, but it didn't" + void doesNotCrashesOnError(@TempDir final Path temp) throws Exception { + MatcherAssert.assertThat( + new FakeMaven(temp) + .withProgram("something < is wrong here") + .execute(new FakeMaven.Parse()) + .result(), + Matchers.hasKey( + String.format("target/%s/foo/x/main.%s", ParseMojo.DIR, TranspileMojo.EXT) + ) ); } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java index 50aa402932..e5e9525d19 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java @@ -124,6 +124,44 @@ void failsOptimizationOnError(@TempDir final Path temp) { ); } + @Test + void failsOptimizationOnCritical(@TempDir final Path temp) { + Assertions.assertThrows( + IllegalStateException.class, + () -> new FakeMaven(temp) + .withProgram( + "+package f\n", + "[args] > main", + " seq > @", + " TRUE > x", + " FALSE > x" + ).with("trackOptimizationSteps", true) + .execute(new FakeMaven.Verify()) + ); + } + + @Test + void failsParsingOnError(@TempDir final Path temp) { + Assertions.assertThrows( + IllegalStateException.class, + () -> new FakeMaven(temp) + .withProgram("something > is wrong here") + .execute(new FakeMaven.Verify()), + "Program with invalid syntax should have failed, but it didn't" + ); + } + + @Test + void failsOnInvalidProgram(@TempDir final Path temp) { + Assertions.assertThrows( + IllegalStateException.class, + () -> new FakeMaven(temp) + .withProgram(AssembleMojoTest.INVALID_PROGRAM) + .execute(new FakeMaven.Verify()), + "Invalid program with wrong syntax should have failed to assemble, but it didn't" + ); + } + @Test void failsOnWarning(@TempDir final Path temp) throws Exception { final FakeMaven maven = new FakeMaven(temp) From f92ffec03683d3a2b97da74eee1ab964fa3c7a87 Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Tue, 12 Dec 2023 18:40:54 +0300 Subject: [PATCH 13/14] #2678 fix SafeMojo --- .../src/test/java/org/eolang/maven/SafeMojoTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java index 9c64468535..24ee94bce9 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/SafeMojoTest.java @@ -42,11 +42,10 @@ final class SafeMojoTest { @Test @CaptureLogs void logsStackTrace(final Logs out, @TempDir final Path temp) { - Assertions.assertThrows( - IllegalStateException.class, + Assertions.assertDoesNotThrow( () -> new FakeMaven(temp) .withProgram("something > is definitely wrong here") - .execute(new FakeMaven.Verify()) + .execute(new FakeMaven.Parse()) ); MatcherAssert.assertThat( String.join("\n", out.captured()), From 6056bfc61ed8d2e9cd5fc4711e201cd8fe1a20a2 Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:33:31 +0300 Subject: [PATCH 14/14] #2678 appropriate use of TrClasspath --- .../src/main/java/org/eolang/maven/VerifyMojo.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java index 55d06bc251..db65d428a8 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java @@ -104,11 +104,10 @@ void exec() throws IOException { */ private Optimization optimization() { Optimization opt = new OptTrain( - new TrClasspath<>( - new TrDefault<>(), - "/org/eolang/parser/fail-on-errors.xsl", - "/org/eolang/parser/fail-on-critical.xsl" - ).back() + new TrClasspath<>(new TrDefault<>()) + .with("/org/eolang/parser/fail-on-errors.xsl") + .with("/org/eolang/parser/fail-on-critical.xsl") + .back() ); if (this.failOnWarning) { opt = new OptTrain(opt, "/org/eolang/parser/fail-on-warnings.xsl");