From 3f8f19910ac8ecae55ec64e76d6093a23f8ebdff Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 27 Jul 2023 14:33:28 +0300 Subject: [PATCH 1/5] feat(#2270): add ObjectionaryCommitHashes --- .../java/org/eolang/maven/hash/ChRemote.java | 2 +- .../eolang/maven/hash/CommitHashesMap.java | 16 ++-- .../eolang/maven/hash/CommitHashesText.java | 87 ------------------- .../maven/hash/ObjectionaryCommitHashes.java | 78 +++++++++++++++++ 4 files changed, 89 insertions(+), 94 deletions(-) delete mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java index 193c0a4228..615623e49c 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java @@ -37,7 +37,7 @@ public final class ChRemote implements CommitHash { /** * Cached text of hashes. */ - private static final Text CACHE = new Sticky(new CommitHashesText()); + private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes().load()); /** * Tag. 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..932a94daf1 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 @@ -24,6 +24,7 @@ package org.eolang.maven.hash; import org.cactoos.Scalar; +import org.cactoos.Text; import org.cactoos.iterable.Mapped; import org.cactoos.map.MapEntry; import org.cactoos.map.MapEnvelope; @@ -39,18 +40,21 @@ */ public final class CommitHashesMap extends MapEnvelope { - /** - * Ctor. - */ + public CommitHashesMap() { - this(new CommitHashesText()::asString); + this( + new org.cactoos.scalar.Mapped<>( + Text::asString, + new ObjectionaryCommitHashes()::load + ) + ); } /** * Ctor. * @param table Commit hashes table as string. */ - public CommitHashesMap(final String table) { + private CommitHashesMap(final String table) { this(() -> table); } @@ -70,7 +74,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 deleted file mode 100644 index 0ce946d053..0000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 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; - -/** - * Commit hashes table as text 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 { - /** - * Cache. - */ - private static final Text CACHE = new Sticky(CommitHashesText.load()); - - /** - * Tags. - */ - private static final String HOME = "https://home.objectionary.com/tags.txt"; - - @Override - public String asString() throws Exception { - return CommitHashesText.CACHE.asString(); - } - - /** - * 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. - */ - 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; - }; - } -} 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..4b9d506d8d --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java @@ -0,0 +1,78 @@ +/* + * 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.Text; +import org.cactoos.scalar.Unchecked; +import org.cactoos.text.TextOf; + +/** + * CommitHashes which we download from Objectionary. + * + * @since 0.30 + */ +final class ObjectionaryCommitHashes { + + /** + * Tags. + */ + private static final String HOME = "https://home.objectionary.com/tags.txt"; + + /** + * The url from which to download tags list. + */ + private final URL url; + + /** + * 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) { + this.url = tags; + } + + /** + * Load tags (lazy). + * @return Tags. + */ + Text load() { + return new TextOf(this.url); + } +} From 0118603f74c72d7a5b1cd3662689cf66b46ddb37 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 27 Jul 2023 14:37:26 +0300 Subject: [PATCH 2/5] feat(#2270): return CommitHashesText back --- .../java/org/eolang/maven/hash/ChRemote.java | 2 +- .../eolang/maven/hash/CommitHashesMap.java | 8 +--- .../eolang/maven/hash/CommitHashesText.java | 46 +++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java index 615623e49c..193c0a4228 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ChRemote.java @@ -37,7 +37,7 @@ public final class ChRemote implements CommitHash { /** * Cached text of hashes. */ - private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes().load()); + private static final Text CACHE = new Sticky(new CommitHashesText()); /** * Tag. 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 932a94daf1..6f59ed8c90 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 @@ -24,7 +24,6 @@ package org.eolang.maven.hash; import org.cactoos.Scalar; -import org.cactoos.Text; import org.cactoos.iterable.Mapped; import org.cactoos.map.MapEntry; import org.cactoos.map.MapEnvelope; @@ -42,12 +41,7 @@ public final class CommitHashesMap extends MapEnvelope { public CommitHashesMap() { - this( - new org.cactoos.scalar.Mapped<>( - Text::asString, - new ObjectionaryCommitHashes()::load - ) - ); + this(new CommitHashesText()::asString); } /** 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 new file mode 100644 index 0000000000..57885f5daa --- /dev/null +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java @@ -0,0 +1,46 @@ +/* + * 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 org.cactoos.Text; +import org.cactoos.text.Sticky; + +/** + * 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 + */ +public final class CommitHashesText implements Text { + /** + * Cache. + */ + private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes().load()); + + @Override + public String asString() throws Exception { + return CommitHashesText.CACHE.asString(); + } +} From 5babd001f843b26dfd870898667ab9f25ccb05cd Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 27 Jul 2023 14:43:37 +0300 Subject: [PATCH 3/5] feat(#2270): fix all qulice suggestions --- .../src/main/java/org/eolang/maven/hash/CommitHashesMap.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 6f59ed8c90..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 @@ -39,7 +39,9 @@ */ public final class CommitHashesMap extends MapEnvelope { - + /** + * Constructor. + */ public CommitHashesMap() { this(new CommitHashesText()::asString); } From bc9d42b67294dc6453a2ec50201a66683c616b31 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 27 Jul 2023 17:17:47 +0300 Subject: [PATCH 4/5] feat(#2270): make ObjectionaryCommitHashes extend TextEnvelope --- .../eolang/maven/hash/CommitHashesText.java | 2 +- .../maven/hash/ObjectionaryCommitHashes.java | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) 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 57885f5daa..3f411f7a87 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 @@ -37,7 +37,7 @@ public final class CommitHashesText implements Text { /** * Cache. */ - private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes().load()); + private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes()); @Override public String asString() throws Exception { 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 index 4b9d506d8d..c36636f48b 100644 --- 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 @@ -24,8 +24,8 @@ package org.eolang.maven.hash; import java.net.URL; -import org.cactoos.Text; import org.cactoos.scalar.Unchecked; +import org.cactoos.text.TextEnvelope; import org.cactoos.text.TextOf; /** @@ -33,18 +33,13 @@ * * @since 0.30 */ -final class ObjectionaryCommitHashes { +final class ObjectionaryCommitHashes extends TextEnvelope { /** * Tags. */ private static final String HOME = "https://home.objectionary.com/tags.txt"; - /** - * The url from which to download tags list. - */ - private final URL url; - /** * Constructor. */ @@ -65,14 +60,6 @@ private ObjectionaryCommitHashes(final String tags) { * @param tags The url from which to download tags list. */ private ObjectionaryCommitHashes(final URL tags) { - this.url = tags; - } - - /** - * Load tags (lazy). - * @return Tags. - */ - Text load() { - return new TextOf(this.url); + super(new TextOf(tags)); } } From 10e35f9b095038078c105a474dc4314bee213b98 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Thu, 27 Jul 2023 18:43:21 +0300 Subject: [PATCH 5/5] feat(#2270): Make CommitHashesText extend TextEnvelope --- .../eolang/maven/hash/CommitHashesText.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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 3f411f7a87..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 @@ -25,6 +25,7 @@ import org.cactoos.Text; import org.cactoos.text.Sticky; +import org.cactoos.text.TextEnvelope; /** * Commit hashes table as text from objectionary. @@ -33,14 +34,25 @@ * * @since 0.29.6 */ -public final class CommitHashesText implements Text { +final class CommitHashesText extends TextEnvelope { + /** * Cache. */ private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes()); - @Override - public String asString() throws Exception { - return CommitHashesText.CACHE.asString(); + /** + * Constructor. + */ + CommitHashesText() { + this(CommitHashesText.CACHE); + } + + /** + * Constructor. + * @param text The text to of commit hashes. + */ + private CommitHashesText(final Text text) { + super(text); } }