diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesMap.java b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesMap.java index d682b7d7e8..816ede10ae 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesMap.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesMap.java @@ -40,7 +40,7 @@ public final class CommitHashesMap extends MapEnvelope { /** - * Ctor. + * Constructor. */ public CommitHashesMap() { this(new CommitHashesText()::asString); @@ -50,7 +50,7 @@ public CommitHashesMap() { * Ctor. * @param table Commit hashes table as string. */ - public CommitHashesMap(final String table) { + private CommitHashesMap(final String table) { this(() -> table); } @@ -70,7 +70,7 @@ public CommitHashesMap(final String table) { * So in order to avoid problems it would be better not to cut hashes here * but when necessary. */ - public CommitHashesMap(final Scalar table) { + private CommitHashesMap(final Scalar table) { super( new MapOf<>( new Mapped<>( diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java index 0ce946d053..ebff33711c 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java @@ -23,65 +23,36 @@ */ package org.eolang.maven.hash; -import com.jcabi.log.Logger; -import java.io.IOException; -import java.net.URL; import org.cactoos.Text; import org.cactoos.text.Sticky; -import org.cactoos.text.TextOf; -import org.cactoos.text.UncheckedText; +import org.cactoos.text.TextEnvelope; /** * Commit hashes table as text from objectionary. + * This class serves the purpose of the global cache in order to avoid + * downloading the list of tags multiple times from objectionary. * * @since 0.29.6 - * @todo #1602:30min Come up with a good name for the class. There are many - * things we want to say with the name of the class: 1) it's commit hashes - * 2) it's a text 3) it's loaded from the objectionary. The result name will be - * ObjectionaryCommitHashesText and it may look a bit verbose. Maybe it really - * does not but we should decide anyway. */ -public final class CommitHashesText implements Text { +final class CommitHashesText extends TextEnvelope { + /** * Cache. */ - private static final Text CACHE = new Sticky(CommitHashesText.load()); + private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes()); /** - * Tags. + * Constructor. */ - private static final String HOME = "https://home.objectionary.com/tags.txt"; - - @Override - public String asString() throws Exception { - return CommitHashesText.CACHE.asString(); + CommitHashesText() { + this(CommitHashesText.CACHE); } /** - * Load commit hashes from objectionary only once. - * @return Commit hashes from objectionary. - * @todo #1602:30min What is the reason for this exception swallowing and - * returning an empty string? Why can't we just escalate/rethrow it? - * Now it looks pretty weird/wrong. + * Constructor. + * @param text The text to of commit hashes. */ - private static Text load() { - return () -> { - String text; - try { - text = new UncheckedText( - new TextOf( - new URL(CommitHashesText.HOME) - ) - ).asString(); - } catch (final IOException ex) { - Logger.warn( - CommitHashesText.class, - "Failed to load catalog of Git hashes from %s, because of %s: '%s'", - CommitHashesText.HOME, ex.getClass().getSimpleName(), ex.getMessage() - ); - text = ""; - } - return text; - }; + private CommitHashesText(final Text text) { + super(text); } } diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java new file mode 100644 index 0000000000..c36636f48b --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java @@ -0,0 +1,65 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2016-2023 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.hash; + +import java.net.URL; +import org.cactoos.scalar.Unchecked; +import org.cactoos.text.TextEnvelope; +import org.cactoos.text.TextOf; + +/** + * CommitHashes which we download from Objectionary. + * + * @since 0.30 + */ +final class ObjectionaryCommitHashes extends TextEnvelope { + + /** + * Tags. + */ + private static final String HOME = "https://home.objectionary.com/tags.txt"; + + /** + * Constructor. + */ + ObjectionaryCommitHashes() { + this(ObjectionaryCommitHashes.HOME); + } + + /** + * Constructor. + * @param tags The url from which to download tags list. + */ + private ObjectionaryCommitHashes(final String tags) { + this(new Unchecked<>(() -> new URL(tags)).value()); + } + + /** + * Constructor. + * @param tags The url from which to download tags list. + */ + private ObjectionaryCommitHashes(final URL tags) { + super(new TextOf(tags)); + } +}