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/main/java/org/eolang/maven/BinarizeParseMojo.java b/eo-maven-plugin/src/main/java/org/eolang/maven/BinarizeParseMojo.java index c4b1fcaa06..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 @@ -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.BiFunction; 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; @@ -74,7 +76,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() @@ -84,6 +86,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) @@ -145,29 +162,16 @@ private XML addFFIs( * Add ffi node via xsl transformation and return list of them. * @param input Input xmir. * @return FFI nodes. - * @todo #2649:90min This method may be more general. We need to get rid from rust dependencies - * in this method, because when adding another type of inserts it will be just copy-paste here. - * First of all, the for-loop must create all kinds of FFI nodes, not only {@link RustNode}. I - * think we can implement it, using something like {@code FFINodeFactory}, that will return - * appropriate FFI node for every XML node from {@code nodes}. Also it will be great to move - * paths to XML FFI insert nodes (such as {@code "/program/rusts/rust"}) from this method to - * a static class field. * @checkstyle AbbreviationAsWordInNameCheck (8 lines) */ private Collection getFFIs(final XML input) { - final List nodes = this.addFFIs(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.addFFIs(input); + BinarizeParseMojo.FACTORY.forEach( + (xpath, ctor) -> injected + .nodes(xpath) + .forEach(node -> ret.add(ctor.apply(node, this))) + ); return ret; } 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 af19bdf09f..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 @@ -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. @@ -176,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) @@ -190,18 +179,10 @@ 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() - ) - ); - } } } } 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..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 @@ -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,10 @@ 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<>()) + .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"); 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..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,32 +215,20 @@ void assemblesTogetherWithVersions(@TempDir final Path temp) throws Exception { } @Test - void assemblesNotFailWithFailOnErrorFlag(@TempDir final Path temp) throws IOException { + void assemblesNotFailWithFailOnError(@TempDir final Path temp) throws IOException { final Map result = new FakeMaven(temp) .withProgram(AssembleMojoTest.INVALID_PROGRAM) - .with("failOnError", false) - .execute(AssembleMojo.class).result(); + .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( - "Since the eo program invalid we shouldn't have optimized it, but we did", + "Even if the eo program invalid we still have to optimize it, but we didn't", result.get(String.format("target/%s", OptimizeMojo.DIR)), - Matchers.not(new ContainsFiles(String.format("**/main.%s", TranspileMojo.EXT))) - ); - } - - @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) + new ContainsFiles(String.format("**/main.%s", TranspileMojo.EXT)) ); } 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/OptimizeMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OptimizeMojoTest.java index 82aab5f6d7..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", @@ -231,6 +230,10 @@ void failsOnCritical(@TempDir final Path temp) throws IOException { " FALSE > x" ).with("trackOptimizationSteps", true) .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 c154c3a033..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,25 +116,10 @@ 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") - .with("failOnError", true) - .execute(ParseMojo.class) - ).getCause().getCause().getMessage(), - Matchers.containsString("Failed to parse") - ); - } - - @Test - void doesNotCrashesWithFailOnError(@TempDir final Path temp) throws Exception { + void doesNotCrashesOnError(@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( 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..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,12 +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") - .with("failOnError", true) - .execute(ParseMojo.class) + .execute(new FakeMaven.Parse()) ); MatcherAssert.assertThat( String.join("\n", out.captured()), 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)