Skip to content

Commit

Permalink
Merge branch 'master' into feat/#3092/snippet-phi-unphi-test
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon authored May 2, 2024
2 parents 5a10444 + 7b44858 commit a0c917e
Show file tree
Hide file tree
Showing 33 changed files with 485 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/simian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
distribution: 'temurin'
java-version: 17
- run: wget --quiet http://public.yegor256.com/simian.jar -O /tmp/simian.jar
- run: java -jar /tmp/simian.jar -threshold=19 "-excludes=**/gen" "-excludes=**/it" "**/*.java"
- run: java -jar /tmp/simian.jar -threshold=15 "-excludes=**/gen" "-excludes=**/it" "**/*.java"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ target/
.classpath
.recommenders
.mvn/wrapper/maven-wrapper.jar
.factorypath
.factorypath
eo-maven-plugin/lib
eo-runtime/lib
2 changes: 1 addition & 1 deletion eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ SOFTWARE.
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.1</version>
<version>1.17.0</version>
</dependency>
<dependency>
<groupId>org.twdata.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.jcabi.log.Logger;
import org.cactoos.Text;
import org.cactoos.text.Sticky;

/**
* Hash of tag from objectionary.
Expand All @@ -37,7 +36,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 CommitHashesText();

/**
* Tag.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
*/
package org.eolang.maven.hash;

import org.cactoos.Scalar;

/**
* Hash of tag.
*
* @since 0.28.11
*/
public interface CommitHash {
@FunctionalInterface
public interface CommitHash extends Scalar<String> {

/**
* SHA Hash.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
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;

Expand All @@ -49,15 +47,13 @@ final class CommitHashesText extends TextEnvelope {
/**
* Cache.
*/
private static final Text CACHE = new Sticky(
CommitHashesText.asText(CommitHashesText.HOME)
);
private static final String CACHE = CommitHashesText.asText(CommitHashesText.HOME);

/**
* Constructor.
*/
CommitHashesText() {
super(CommitHashesText.CACHE);
super(() -> CommitHashesText.CACHE);
}

/**
Expand All @@ -66,10 +62,9 @@ final class CommitHashesText extends TextEnvelope {
* @return The body of the web page
*/
@RetryOnFailure(delay = 1L, unit = TimeUnit.SECONDS)
private static Text asText(final String url) {
final String body = new Unchecked<>(
private static String asText(final String url) {
return new Unchecked<>(
() -> new TextOf(new URL(url)).asString()
).value();
return new TextOf(body);
}
}
87 changes: 48 additions & 39 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/HmBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.cactoos.Input;
import org.cactoos.Text;
import org.cactoos.bytes.BytesOf;
import org.cactoos.io.InputOf;
import org.cactoos.io.OutputTo;
import org.cactoos.io.TeeInput;
import org.cactoos.scalar.IoChecked;
Expand All @@ -51,6 +50,11 @@ public final class HmBase implements Home {
*/
private final Path cwd;

/**
* Home with "save" functionality.
*/
private final Home origin;

/**
* Ctor.
*
Expand All @@ -63,63 +67,68 @@ public HmBase(final File file) {
/**
* Ctor.
*
* @param path Path
* @param pth Path
*/
public HmBase(final Path path) {
this.cwd = path;
public HmBase(final Path pth) {
this.cwd = pth;
this.origin = new HmSave(
(input, path) -> {
final Path target = this.absolute(this.onlyRelative(path));
if (target.toFile().getParentFile().mkdirs()) {
Logger.debug(
this, "Directory created: %s",
new Rel(target.getParent())
);
}
try {
final long bytes = new IoChecked<>(
new LengthOf(
new TeeInput(
input,
new OutputTo(target)
)
)
).value();
Logger.debug(
HmBase.class, "File %s saved (%d bytes)",
target, bytes
);
} catch (final IOException ex) {
throw new IOException(
String.format(
"Failed while trying to save to %s",
target
),
ex
);
}
}
);
}

@Override
public void save(final String str, final Path path) throws IOException {
this.save(new InputOf(str), path);
this.origin.save(str, path);
}

@Override
public void save(final Text txt, final Path path) throws IOException {
this.save(new InputOf(txt), path);
this.origin.save(txt, path);
}

@Override
public void save(final InputStream stream, final Path path) throws IOException {
this.save(new InputOf(stream), path);
public void save(final InputStream stream, final Path path) throws IOException {
this.origin.save(stream, path);
}

@Override
public void save(final byte[] bytes, final Path path) throws IOException {
this.save(new InputOf(bytes), path);
public void save(final byte[] bytes, final Path path) throws IOException {
this.origin.save(bytes, path);
}

@Override
public void save(final Input input, final Path path) throws IOException {
final Path target = this.absolute(this.onlyRelative(path));
if (target.toFile().getParentFile().mkdirs()) {
Logger.debug(
this, "Directory created: %s",
new Rel(target.getParent())
);
}
try {
final long bytes = new IoChecked<>(
new LengthOf(
new TeeInput(
input,
new OutputTo(target)
)
)
).value();
Logger.debug(
HmBase.class, "File %s saved (%d bytes)",
target, bytes
);
} catch (final IOException ex) {
throw new IOException(
String.format(
"Failed while trying to save to %s",
target
),
ex
);
}
this.origin.save(input, path);
}

@Override
Expand Down
35 changes: 22 additions & 13 deletions eo-maven-plugin/src/main/java/org/eolang/maven/util/HmOptional.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.cactoos.Bytes;
import org.cactoos.Input;
import org.cactoos.Text;
import org.cactoos.io.InputOf;

/**
* Location for files that saves optionally.
Expand All @@ -43,6 +42,11 @@ public final class HmOptional implements Home {
*/
private final Home origin;

/**
* Home with "save" functionality.
*/
private final Home sve;

/**
* Rewrite files or not.
*/
Expand All @@ -57,36 +61,41 @@ public final class HmOptional implements Home {
public HmOptional(final Home home, final boolean rwte) {
this.origin = home;
this.rewrite = rwte;
this.sve = new HmSave(
(input, path) -> {
final Path target = this.absolute(this.onlyRelative(path));
if (!target.toFile().exists() || this.rewrite) {
this.origin.save(input, path);
} else {
Logger.info(this, "Rewriting of the %s file was skipped", target);
}
}
);
}

@Override
public void save(final String str, final Path path) throws IOException {
this.save(new InputOf(str), path);
this.sve.save(str, path);
}

@Override
public void save(final Text txt, final Path path) throws IOException {
this.save(new InputOf(txt), path);
this.sve.save(txt, path);
}

@Override
public void save(final InputStream stream, final Path path) throws IOException {
this.save(new InputOf(stream), path);
public void save(final InputStream stream, final Path path) throws IOException {
this.sve.save(stream, path);
}

@Override
public void save(final byte[] bytes, final Path path) throws IOException {
this.save(new InputOf(bytes), path);
public void save(final byte[] bytes, final Path path) throws IOException {
this.sve.save(bytes, path);
}

@Override
public void save(final Input input, final Path path) throws IOException {
final Path target = this.absolute(this.onlyRelative(path));
if (!target.toFile().exists() || this.rewrite) {
this.origin.save(input, path);
} else {
Logger.info(this, "Rewriting of the %s file was skipped", target);
}
this.sve.save(input, path);
}

@Override
Expand Down
Loading

1 comment on commit a0c917e

@0pdd
Copy link

@0pdd 0pdd commented on a0c917e May 3, 2024

Choose a reason for hiding this comment

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

Puzzle 3092-ad9ee9a7 discovered in eo-runtime/src/test/java/org/eolang/SnippetTestCase.java) and submitted as #3162. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.