Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 28, 2023
2 parents 032cd80 + 10e35f9 commit 674a84f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public final class CommitHashesMap extends MapEnvelope<String, CommitHash> {

/**
* Ctor.
* Constructor.
*/
public CommitHashesMap() {
this(new CommitHashesText()::asString);
Expand All @@ -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);
}

Expand All @@ -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<String> table) {
private CommitHashesMap(final Scalar<String> table) {
super(
new MapOf<>(
new Mapped<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

2 comments on commit 674a84f

@0pdd
Copy link

@0pdd 0pdd commented on 674a84f Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1602-d66ec8b5 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java), that's why I closed #2270. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 674a84f Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1602-ebb101bb disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/hash/CommitHashesText.java), that's why I closed #2271. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.