diff --git a/eo-maven-plugin/src/main/java/org/eolang/maven/OyRemote.java b/eo-maven-plugin/src/main/java/org/eolang/maven/OyRemote.java
index 5334b975de..fd9b262b94 100644
--- a/eo-maven-plugin/src/main/java/org/eolang/maven/OyRemote.java
+++ b/eo-maven-plugin/src/main/java/org/eolang/maven/OyRemote.java
@@ -41,7 +41,7 @@ final class OyRemote implements Objectionary {
/**
* The address template.
*/
- private final String template;
+ private final UrlOy template;
/**
* Constructor.
@@ -49,22 +49,20 @@ final class OyRemote implements Objectionary {
* @throws IOException if fails.
*/
OyRemote(final CommitHash hash) throws IOException {
- this.template = String.format(
- "https://raw.githubusercontent.com/objectionary/home/%s/objects/%%s.eo",
+ this.template = new UrlOy(
+ "https://raw.githubusercontent.com/objectionary/home/%s/objects/%s.eo",
hash.value()
);
}
@Override
public String toString() {
- return this.template;
+ return this.template.toString();
}
@Override
public Input get(final String name) throws MalformedURLException {
- final URL url = new URL(
- String.format(this.template, name.replace(".", "/"))
- );
+ final URL url = this.template.value(name);
Logger.debug(
this, "The object '%s' will be pulled from %s...",
name, url
@@ -72,4 +70,60 @@ public Input get(final String name) throws MalformedURLException {
return new InputOf(url);
}
+ /**
+ * Objectionary URL template.
+ * Assumes two placeholders in terms of
+ * {@link String#format(String, Object...)}: 1st for version hash,
+ * 2nd for program name.
+ *
Example: "https://raw.githubusercontent.com/objectionary/home/%s/objects/%s.eo"
+ *
+ * @since 1.0
+ */
+ static final class UrlOy {
+
+ /**
+ * URL template. Expects two placeholders in terms of
+ * {@link String#format(String, Object...)}: 1st for hash,
+ * 2nd for program name.
+ *
Example: "https://raw.githubusercontent.com/objectionary/home/%s/objects/%s.eo"
+ */
+ private final String template;
+
+ /**
+ * Objects version hash.
+ */
+ private final String hash;
+
+ /**
+ * Ctor.
+ * @param template URL template.
+ * @param hash Objects version hash.
+ */
+ UrlOy(final String template, final String hash) {
+ this.template = template;
+ this.hash = hash;
+ }
+
+ /**
+ * URL for the program.
+ * @param name Fully qualified EO program name as specified by {@link Place}
+ * @return URL
+ * @throws MalformedURLException in case of incorrect URL
+ */
+ public URL value(final String name) throws MalformedURLException {
+ return new URL(
+ String.format(
+ this.template,
+ this.hash,
+ name.replace(".", "/")
+ )
+ );
+ }
+
+ @Override
+ public String toString() {
+ return this.template;
+ }
+ }
+
}
diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/OyRemoteTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/OyRemoteTest.java
new file mode 100644
index 0000000000..6655b3e77d
--- /dev/null
+++ b/eo-maven-plugin/src/test/java/org/eolang/maven/OyRemoteTest.java
@@ -0,0 +1,63 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2016-2022 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;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Test for {@link OyRemote}.
+ *
+ * @since 1.0
+ */
+final class OyRemoteTest {
+
+ @Test
+ void buildsCorrectUrl() throws Exception {
+ MatcherAssert.assertThat(
+ new OyRemote.UrlOy(
+ "https://raw/objectionary/home/%s/objects/%s.eo",
+ "abcde"
+ ).value("org.eolang.app"),
+ Matchers.is(
+ new URL("https://raw/objectionary/home/abcde/objects/org/eolang/app.eo")
+ )
+ );
+ }
+
+ @Test
+ void throwsExceptionOnInvalidUrl() {
+ Assertions.assertThrows(
+ MalformedURLException.class,
+ () -> new OyRemote.UrlOy(
+ "hts:raw.githubusercontent.com/objectionary/home/%s/objects/%s.eo",
+ "abcde"
+ ).value("org.eolang.app")
+ );
+ }
+}