diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptCached.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptCached.java index b8bc56ba10..6761134212 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptCached.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptCached.java @@ -25,7 +25,6 @@ import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; -import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -55,7 +54,7 @@ public final class OptCached implements Optimization { private final Optimization delegate; /** - * Cache folder. + * Absolute path of cache folder. */ private final Path folder; @@ -74,7 +73,7 @@ public OptCached( } @Override - public XML apply(final Path path) throws FileNotFoundException { + public XML apply(final Path path) throws Exception { try { final XML optimized; if (this.contains(path)) { @@ -89,8 +88,8 @@ public XML apply(final Path path) throws FileNotFoundException { } return optimized; } catch (final IOException ex) { - throw new IllegalStateException( - String.format("Can't optimize '%s'", new XMLDocument(path)), + throw new IOException( + String.format("Can't optimize '%s'", path), ex ); } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java index 95a44fb6a6..2b1312ed56 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptSpy.java @@ -28,7 +28,6 @@ import com.jcabi.xml.XMLDocument; import com.yegor256.xsline.Shift; import com.yegor256.xsline.Train; -import java.io.FileNotFoundException; import java.nio.file.Path; import org.eolang.maven.Place; import org.eolang.maven.SpyTrain; @@ -68,7 +67,7 @@ public OptSpy(final Train trn, final Path target) { } @Override - public XML apply(final Path path) throws FileNotFoundException { + public XML apply(final Path path) throws Exception { final Path dir = new Place( new XMLDocument(path) .xpath("/program/@name") diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java index a1c5d196ac..fc51d8f1c1 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/OptTrain.java @@ -32,7 +32,6 @@ import com.yegor256.xsline.TrFast; import com.yegor256.xsline.Train; import com.yegor256.xsline.Xsline; -import java.io.FileNotFoundException; import java.nio.file.Path; /** @@ -120,7 +119,7 @@ public OptTrain( } @Override - public XML apply(final Path path) throws FileNotFoundException { + public XML apply(final Path path) throws Exception { return new Xsline(this.shifts).pass(this.delegate.apply(path)); } } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/Optimization.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/Optimization.java index 9fcab4f367..79f3398c11 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/Optimization.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/Optimization.java @@ -24,9 +24,8 @@ package org.eolang.maven.optimization; import com.jcabi.xml.XML; -import java.io.FileNotFoundException; import java.nio.file.Path; -import java.util.function.Function; +import org.cactoos.Func; /** * Abstraction for XML optimizations. @@ -34,20 +33,5 @@ * @since 0.28.11 */ @FunctionalInterface -public interface Optimization extends ThrowingFunction { - - /** - * Return function if it works without exception. - * - * @return The function result - */ - default Function unchecked() { - return input -> { - try { - return this.apply(input); - } catch (final FileNotFoundException exception) { - throw new PathNotFoundException(input, exception); - } - }; - } +public interface Optimization extends Func { } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/PathNotFoundException.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/PathNotFoundException.java deleted file mode 100644 index e5217b504a..0000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/PathNotFoundException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.optimization; - -import java.nio.file.Path; - -/** - * If the path isn't valid. - * @since 0.35.0 - */ -public class PathNotFoundException extends RuntimeException { - - /** - * Ctor. - * @param path The path. - * @param cause The cause. - */ - PathNotFoundException(final Path path, final Throwable cause) { - super( - String.format( - "Cannot get XML from path '%s'", path - ), - cause - ); - } -} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/ThrowingFunction.java b/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/ThrowingFunction.java deleted file mode 100644 index 8ce430e936..0000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/optimization/ThrowingFunction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.optimization; - -/** - * Abstraction for XML optimizations. - * @param Input type. - * @param Return type. - * @param Exception type. - * @since 0.35.0 - */ -@FunctionalInterface -public interface ThrowingFunction { - /** - * Applies this function to the given argument. - * - * @param input The function argument - * @return The function result - * @throws E If fails - */ - R apply(I input) throws E; -} diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java index 01947f1497..2d5583b11f 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/optimization/OptCachedTest.java @@ -59,7 +59,7 @@ final class OptCachedTest { */ @Test void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path cache, @TempDir final Path dir) - throws IOException { + throws Exception { final XML xml = OptCachedTest.program(); final FileTime time = FileTime.fromMillis(System.currentTimeMillis()); final Path program = OptCachedTest.save(dir, xml); @@ -83,7 +83,7 @@ void returnsFromCacheButTimesSaveAndExecuteDifferent( @TempDir final Path cache, @TempDir final Path dir ) - throws IOException { + throws Exception { final XML xml = OptCachedTest.program(); final Path program = OptCachedTest.save(dir, xml); OptCachedTest.setTime( @@ -109,7 +109,7 @@ void returnsFromCacheButTimesSaveAndExecuteDifferent( @Test void returnsFromCacheCorrectProgram(@TempDir final Path cache, @TempDir final Path dir) - throws IOException { + throws Exception { final Path cached = OptCachedTest.save( cache, OptCachedTest.program("first program") @@ -134,7 +134,7 @@ void returnsFromCacheCorrectProgram(@TempDir final Path cache, @TempDir final Pa @Test void optimizesIfXmlIsAbsentInCache(@TempDir final Path cache, @TempDir final Path dir) - throws IOException { + throws Exception { final Path program = OptCachedTest.save(dir, OptCachedTest.program()); MatcherAssert.assertThat( "We expect that the program will be created and returned as is (same instance)", @@ -151,7 +151,7 @@ void optimizesIfXmlIsAbsentInCache(@TempDir final Path cache, @TempDir final Pat @Test void optimizesBecauseCacheIsExpired( @TempDir final Path cache, - @TempDir final Path dir) throws IOException { + @TempDir final Path dir) throws Exception { final Path program = OptCachedTest.save( dir, OptCachedTest.program("new program")