From 60701d7114fd2302fc46f6838697a3f43cacd6e6 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 16 Apr 2024 05:35:06 +0300 Subject: [PATCH 1/4] #3089: retry on failure --- eo-maven-plugin/pom.xml | 22 +++++++++++++++++++ .../eolang/maven/objectionary/OyRemote.java | 3 +++ .../maven/objectionary/OyRemoteTest.java | 4 ++-- eo-runtime/src/main/eo/org/eolang/cti.eo | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index 80cae9fbd..790a7f3e0 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -70,6 +70,16 @@ SOFTWARE. jcabi-manifests + + com.jcabi + jcabi-aspects + 0.26.0 + + + org.aspectj + aspectjrt + 1.9.21 + net.sf.saxon Saxon-HE @@ -268,6 +278,18 @@ SOFTWARE. + + com.jcabi + jcabi-maven-plugin + 0.17.0 + + + + ajc + + + + maven-invoker-plugin diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/OyRemote.java b/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/OyRemote.java index 0cc4d403e..699c7129a 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/OyRemote.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/OyRemote.java @@ -23,11 +23,13 @@ */ package org.eolang.maven.objectionary; +import com.jcabi.aspects.RetryOnFailure; import com.jcabi.log.Logger; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.util.concurrent.TimeUnit; import org.cactoos.Input; import org.cactoos.io.InputOf; import org.cactoos.io.InputWithFallback; @@ -84,6 +86,7 @@ public final class OyRemote implements Objectionary { } @Override + @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) public boolean contains(final String name) throws IOException { final int code = ((HttpURLConnection) this.template.value(name).openConnection()) .getResponseCode(); diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/objectionary/OyRemoteTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/objectionary/OyRemoteTest.java index b46c0b1cf..8048fd122 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/objectionary/OyRemoteTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/objectionary/OyRemoteTest.java @@ -46,7 +46,7 @@ final class OyRemoteTest { @Test void buildsCorrectUrl() throws Exception { MatcherAssert.assertThat( - "TO ADD ASSERTION MESSAGE", + "OyRemove.UrlOy generates correct URL", new OyRemote.UrlOy( "https://raw/objectionary/home/%s/objects/%s.eo", "abcde" @@ -74,7 +74,7 @@ final class OyRemoteTest { final CommitHash hash = new ChRemote("master"); final Objectionary objectionary = new OyRemote(hash); MatcherAssert.assertThat( - "TO ADD ASSERTION MESSAGE", + "OyRemote positively checks the presence of the object in Objectionary", objectionary.contains("org.eolang.io.stdout"), Matchers.is(true) ); diff --git a/eo-runtime/src/main/eo/org/eolang/cti.eo b/eo-runtime/src/main/eo/org/eolang/cti.eo index b0f0edde7..a79d6e034 100644 --- a/eo-runtime/src/main/eo/org/eolang/cti.eo +++ b/eo-runtime/src/main/eo/org/eolang/cti.eo @@ -1,6 +1,6 @@ # The MIT License (MIT) # -# 2016-2023 Objectionary.com +# 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 From 61dfeadfad4c9dcd4e7b686cde0e832070e2faa0 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 16 Apr 2024 05:50:42 +0300 Subject: [PATCH 2/4] #3089: retry in ObjectionaryCommitHashes --- .../maven/dependencies/DcsWithRuntime.java | 3 +++ .../maven/hash/ObjectionaryCommitHashes.java | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/dependencies/DcsWithRuntime.java b/eo-maven-plugin/src/main/java/org/eolang/maven/dependencies/DcsWithRuntime.java index 67283e0dd..5502c3d3e 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/dependencies/DcsWithRuntime.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/dependencies/DcsWithRuntime.java @@ -23,10 +23,12 @@ */ package org.eolang.maven.dependencies; +import com.jcabi.aspects.RetryOnFailure; import com.jcabi.xml.XMLDocument; import java.io.IOException; import java.net.URL; import java.util.Iterator; +import java.util.concurrent.TimeUnit; import org.apache.maven.model.Dependency; import org.cactoos.list.ListOf; import org.cactoos.scalar.Sticky; @@ -104,6 +106,7 @@ public final class DcsWithRuntime implements Iterable { * * @return Runtime dependency from Maven Central. */ + @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) private static Unchecked mavenDependency() { final String url = String.format( "https://repo.maven.apache.org/maven2/%s/maven-metadata.xml", 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 0e5f73134..049c957f2 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 @@ -23,7 +23,10 @@ */ package org.eolang.maven.hash; +import com.jcabi.aspects.RetryOnFailure; import java.net.URL; +import java.util.concurrent.TimeUnit; +import org.cactoos.Text; import org.cactoos.scalar.Unchecked; import org.cactoos.text.TextEnvelope; import org.cactoos.text.TextOf; @@ -49,17 +52,28 @@ final class ObjectionaryCommitHashes extends TextEnvelope { /** * Constructor. - * @param tags The url from which to download tags list. + * @param url The URL from which to download tags list. */ - private ObjectionaryCommitHashes(final String tags) { - this(new Unchecked<>(() -> new URL(tags)).value()); + private ObjectionaryCommitHashes(final String url) { + this(new Unchecked<>(() -> new URL(url)).value()); } /** * Constructor. - * @param tags The url from which to download tags list. + * @param url The URL from which to download tags list. */ - private ObjectionaryCommitHashes(final URL tags) { - super(new TextOf(tags)); + private ObjectionaryCommitHashes(final URL url) { + super(ObjectionaryCommitHashes.asText(url)); + } + + /** + * Download from the URL and return the content. + * @param url The URL with tags + * @return The body of the web page + */ + @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) + private static Text asText(final URL url) { + final String body = new TextOf(url).toString(); + return new TextOf(body); } } From a51bce267e70b787fdbd2c89c82f11c309667ebf Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 16 Apr 2024 05:57:54 +0300 Subject: [PATCH 3/4] #3089: retry in ObjectsIndex --- .../maven/objectionary/ObjectsIndex.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java b/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java index 7e0d6b8bf..2e1ecc0ef 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java @@ -23,8 +23,10 @@ */ package org.eolang.maven.objectionary; +import com.jcabi.aspects.RetryOnFailure; import java.net.URL; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.cactoos.Scalar; import org.cactoos.Text; import org.cactoos.iterable.Mapped; @@ -42,6 +44,11 @@ import org.cactoos.text.TextOf; */ final class ObjectsIndex { + /** + * Tags. + */ + private static final String HOME = "https://home.objectionary.com/objectionary.lst"; + /** * Cached objects index. */ @@ -59,9 +66,7 @@ final class ObjectsIndex { new Mapped<>( Text::asString, new Split( - new TextOf( - new URL("https://home.objectionary.com/objectionary.lst") - ), + ObjectsIndex.asText(new URL(ObjectsIndex.HOME)), "\n" ) ) @@ -102,4 +107,15 @@ final class ObjectsIndex { .replace('/', '.') .substring(name.indexOf('/') + 1); } + + /** + * Download from the URL and return the content. + * @param url The URL with tags + * @return The body of the web page + */ + @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) + private static Text asText(final URL url) { + final String body = new TextOf(url).toString(); + return new TextOf(body); + } } From f099a554bd3c49b7d303c2c563e5d2f0a99632a9 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Tue, 16 Apr 2024 06:20:09 +0300 Subject: [PATCH 4/4] #3089: fix --- .../eolang/maven/hash/CommitHashesText.java | 29 +++++-- .../maven/hash/ObjectionaryCommitHashes.java | 79 ------------------- .../maven/objectionary/ObjectsIndex.java | 3 +- .../maven/hash/CommitHashesTextTest.java | 48 +++++++++++ 4 files changed, 73 insertions(+), 86 deletions(-) delete mode 100644 eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java create mode 100644 eo-maven-plugin/src/test/java/org/eolang/maven/hash/CommitHashesTextTest.java 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 d09128fa8..1e3465021 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,9 +23,14 @@ */ package org.eolang.maven.hash; +import com.jcabi.aspects.RetryOnFailure; +import java.net.URL; +import java.util.concurrent.TimeUnit; import org.cactoos.Text; +import org.cactoos.scalar.Unchecked; import org.cactoos.text.Sticky; import org.cactoos.text.TextEnvelope; +import org.cactoos.text.TextOf; /** * Commit hashes table as text from objectionary. @@ -36,23 +41,35 @@ import org.cactoos.text.TextEnvelope; */ final class CommitHashesText extends TextEnvelope { + /** + * Tags. + */ + private static final String HOME = "https://home.objectionary.com/tags.txt"; + /** * Cache. */ - private static final Text CACHE = new Sticky(new ObjectionaryCommitHashes()); + private static final Text CACHE = new Sticky( + CommitHashesText.asText(CommitHashesText.HOME) + ); /** * Constructor. */ CommitHashesText() { - this(CommitHashesText.CACHE); + super(CommitHashesText.CACHE); } /** - * Constructor. - * @param text The text to of commit hashes. + * Download from the URL and return the content. + * @param url The URL with tags + * @return The body of the web page */ - private CommitHashesText(final Text text) { - super(text); + @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) + private static Text asText(final String url) { + final String body = new Unchecked<>( + () -> new TextOf(new URL(url)).asString() + ).value(); + return new TextOf(body); } } 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 deleted file mode 100644 index 049c957f2..000000000 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/hash/ObjectionaryCommitHashes.java +++ /dev/null @@ -1,79 +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.hash; - -import com.jcabi.aspects.RetryOnFailure; -import java.net.URL; -import java.util.concurrent.TimeUnit; -import org.cactoos.Text; -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 url The URL from which to download tags list. - */ - private ObjectionaryCommitHashes(final String url) { - this(new Unchecked<>(() -> new URL(url)).value()); - } - - /** - * Constructor. - * @param url The URL from which to download tags list. - */ - private ObjectionaryCommitHashes(final URL url) { - super(ObjectionaryCommitHashes.asText(url)); - } - - /** - * Download from the URL and return the content. - * @param url The URL with tags - * @return The body of the web page - */ - @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) - private static Text asText(final URL url) { - final String body = new TextOf(url).toString(); - return new TextOf(body); - } -} diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java b/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java index 2e1ecc0ef..3fca86a14 100644 --- a/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java +++ b/eo-maven-plugin/src/main/java/org/eolang/maven/objectionary/ObjectsIndex.java @@ -32,6 +32,7 @@ import org.cactoos.Text; import org.cactoos.iterable.Mapped; import org.cactoos.scalar.ScalarOf; import org.cactoos.scalar.Sticky; +import org.cactoos.scalar.Unchecked; import org.cactoos.set.SetOf; import org.cactoos.text.Split; import org.cactoos.text.TextOf; @@ -115,7 +116,7 @@ final class ObjectsIndex { */ @RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS) private static Text asText(final URL url) { - final String body = new TextOf(url).toString(); + final String body = new Unchecked<>(() -> new TextOf(url).asString()).value(); return new TextOf(body); } } diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/hash/CommitHashesTextTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/hash/CommitHashesTextTest.java new file mode 100644 index 000000000..f9b454d8a --- /dev/null +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/hash/CommitHashesTextTest.java @@ -0,0 +1,48 @@ +/* + * 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.hash; + +import com.yegor256.WeAreOnline; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Test case for {@link CommitHashesText}. + * + * @since 0.37.0 + */ +final class CommitHashesTextTest { + + @Test + @ExtendWith(WeAreOnline.class) + void downloadsDefaultList() throws Exception { + MatcherAssert.assertThat( + "CommitHashesText downloads the default list of hashes from Objectionary", + new CommitHashesText().asString(), + Matchers.containsString("master") + ); + } +}