From 3258acdc0935b7f4e7da4d970291d8684964d2a8 Mon Sep 17 00:00:00 2001 From: Roman Korostinskiy <70313618+c71n93@users.noreply.github.com> Date: Thu, 2 May 2024 17:34:54 +0300 Subject: [PATCH] #2863 fix namings and qulice violations --- .../java/org/eolang/maven/util/BiIoProc.java | 10 -- .../java/org/eolang/maven/util/HmBase.java | 36 +------ .../java/org/eolang/maven/util/HmNew.java | 63 ----------- .../org/eolang/maven/util/HmOptional.java | 47 ++------ .../java/org/eolang/maven/util/HmSave.java | 100 ++++++++++++++++++ .../main/java/org/eolang/maven/util/Home.java | 8 +- 6 files changed, 119 insertions(+), 145 deletions(-) delete mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/util/BiIoProc.java delete mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/util/HmNew.java create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/util/HmSave.java diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/BiIoProc.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/BiIoProc.java deleted file mode 100644 index 1ccda14ca9..0000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/util/BiIoProc.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.eolang.maven.util; - -import org.cactoos.BiProc; - -import java.io.IOException; - -interface BiIoProc extends BiProc { - @Override - void exec(T t, U u) throws IOException; -} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmBase.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmBase.java index 0c6d9a8a94..0247154a71 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmBase.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmBase.java @@ -33,7 +33,6 @@ import org.cactoos.Input; import org.cactoos.Text; import org.cactoos.bytes.BytesOf; -import org.cactoos.io.InputOf; import org.cactoos.io.OutputTo; import org.cactoos.io.TeeInput; import org.cactoos.scalar.IoChecked; @@ -51,6 +50,9 @@ public final class HmBase implements Home { */ private final Path cwd; + /** + * Home with "save" functionality. + */ private final Home origin; /** @@ -69,7 +71,7 @@ public HmBase(final File file) { */ public HmBase(final Path pth) { this.cwd = pth; - this.origin = new HmNew( + this.origin = new HmSave( (input, path) -> { final Path target = this.absolute(this.onlyRelative(path)); if (target.toFile().getParentFile().mkdirs()) { @@ -104,54 +106,26 @@ public HmBase(final Path pth) { ); } - /** - * Saving string. - * - * @param str String - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final String str, final Path path) throws IOException { this.origin.save(str, path); } - /** - * Saving text. - * - * @param txt Text - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final Text txt, final Path path) throws IOException { this.origin.save(txt, path); } - /** - * Saving stream. - * - * @param stream Input stream - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final InputStream stream, final Path path) throws IOException { this.origin.save(stream, path); } - /** - * Saving bytes. - * - * @param bytes Byte array - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final byte[] bytes, final Path path) throws IOException { this.origin.save(bytes, path); } - + @Override public void save(final Input input, final Path path) throws IOException { this.origin.save(input, path); diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmNew.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmNew.java deleted file mode 100644 index 6ed32df4e8..0000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmNew.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.eolang.maven.util; - -import org.cactoos.Bytes; -import org.cactoos.Input; -import org.cactoos.Text; -import org.cactoos.io.InputOf; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; - -public class HmNew implements Home { - private final BiIoProc sve; - - HmNew(BiIoProc save) { - this.sve = save; - } - - @Override - public void save(String str, Path path) throws IOException { - this.save(new InputOf(str), path); - } - - @Override - public void save(Text txt, Path path) throws IOException { - this.save(new InputOf(txt), path); - } - - @Override - public void save(InputStream stream, Path path) throws IOException { - this.save(new InputOf(stream), path); - } - - @Override - public void save(byte[] bytes, Path path) throws IOException { - this.save(new InputOf(bytes), path); - } - - @Override - public void save(Input input, Path path) throws IOException { - this.sve.exec(input, path); - } - - @Override - public boolean exists(Path path) { - throw new IllegalStateException("Should never happen"); - } - - @Override - public Bytes load(Path path) throws IOException { - throw new IllegalStateException("Should never happen"); - } - - @Override - public Path absolute(Path path) { - throw new IllegalStateException("Should never happen"); - } - - @Override - public Path onlyRelative(Path path) { - throw new IllegalStateException("Should never happen"); - } -} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmOptional.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmOptional.java index 1fc291b5c0..b1c567a706 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmOptional.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmOptional.java @@ -30,7 +30,6 @@ import org.cactoos.Bytes; import org.cactoos.Input; import org.cactoos.Text; -import org.cactoos.io.InputOf; /** * Location for files that saves optionally. @@ -43,7 +42,10 @@ public final class HmOptional implements Home { */ private final Home origin; - private final Home call; + /** + * Home with "save" functionality. + */ + private final Home sve; /** * Rewrite files or not. @@ -59,7 +61,7 @@ public final class HmOptional implements Home { public HmOptional(final Home home, final boolean rwte) { this.origin = home; this.rewrite = rwte; - this.call = new HmNew( + this.sve = new HmSave( (input, path) -> { final Path target = this.absolute(this.onlyRelative(path)); if (!target.toFile().exists() || this.rewrite) { @@ -71,58 +73,29 @@ public HmOptional(final Home home, final boolean rwte) { ); } - - /** - * Saving string. - * - * @param str String - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final String str, final Path path) throws IOException { - this.call.save(str, path); + this.sve.save(str, path); } - /** - * Saving text. - * - * @param txt Text - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final Text txt, final Path path) throws IOException { - this.call.save(txt, path); + this.sve.save(txt, path); } - /** - * Saving stream. - * - * @param stream Input stream - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final InputStream stream, final Path path) throws IOException { - this.call.save(stream, path); + this.sve.save(stream, path); } - /** - * Saving bytes. - * - * @param bytes Byte array - * @param path Cwd-relative path to file - * @throws IOException If fails - */ @Override public void save(final byte[] bytes, final Path path) throws IOException { - this.call.save(bytes, path); + this.sve.save(bytes, path); } @Override public void save(final Input input, final Path path) throws IOException { - this.call.save(input, path); + this.sve.save(input, path); } @Override diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmSave.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmSave.java new file mode 100644 index 0000000000..1e576ad3c9 --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/util/HmSave.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.util; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Path; +import org.cactoos.BiProc; +import org.cactoos.Bytes; +import org.cactoos.Input; +import org.cactoos.Text; +import org.cactoos.io.InputOf; +import org.cactoos.proc.IoCheckedBiProc; + +/** + * Home that defines the logic of saving different types of data to files. + * + * @since 0.37.0 + */ +public final class HmSave implements Home { + /** + * BiProc with two arguments for saving {@link Input} from first argument to file from second. + */ + private final IoCheckedBiProc sve; + + /** + * Ctor. + * + * @param save BiProc for saving {@link Input} to file. + */ + public HmSave(final BiProc save) { + this.sve = new IoCheckedBiProc<>(save); + } + + @Override + public void save(final String str, final Path path) throws IOException { + this.save(new InputOf(str), path); + } + + @Override + public void save(final Text txt, final Path path) throws IOException { + this.save(new InputOf(txt), path); + } + + @Override + public void save(final InputStream stream, final Path path) throws IOException { + this.save(new InputOf(stream), path); + } + + @Override + public void save(final byte[] bytes, final Path path) throws IOException { + this.save(new InputOf(bytes), path); + } + + @Override + public void save(final Input input, final Path path) throws IOException { + this.sve.exec(input, path); + } + + @Override + public boolean exists(final Path path) { + throw new IllegalStateException("Should never happen"); + } + + @Override + public Bytes load(final Path path) throws IOException { + throw new IllegalStateException("Should never happen"); + } + + @Override + public Path absolute(final Path path) { + throw new IllegalStateException("Should never happen"); + } + + @Override + public Path onlyRelative(final Path path) { + throw new IllegalStateException("Should never happen"); + } +} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/util/Home.java b/eo-maven-plugin/src/main/java/org/eolang/maven/util/Home.java index ebd250c7b1..a382ea1a77 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/util/Home.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/util/Home.java @@ -42,7 +42,7 @@ public interface Home { * @param path Cwd-relative path to file * @throws IOException If fails */ - void save(final String str, final Path path) throws IOException; + void save(String str, Path path) throws IOException; /** * Saving text. @@ -51,7 +51,7 @@ public interface Home { * @param path Cwd-relative path to file * @throws IOException If fails */ - void save(final Text txt, final Path path) throws IOException; + void save(Text txt, Path path) throws IOException; /** * Saving stream. @@ -60,7 +60,7 @@ public interface Home { * @param path Cwd-relative path to file * @throws IOException If fails */ - void save(final InputStream stream, final Path path) throws IOException; + void save(InputStream stream, Path path) throws IOException; /** * Saving bytes. @@ -69,7 +69,7 @@ public interface Home { * @param path Cwd-relative path to file * @throws IOException If fails */ - void save(final byte[] bytes, final Path path) throws IOException; + void save(byte[] bytes, Path path) throws IOException; /** * Saving input.