From 64606d3a58e27222cd5a6988f1d0c4dac00d132c Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Mon, 29 Dec 2025 16:17:41 +0300 Subject: [PATCH] refactor(#4780): Remove ContainsFiles class and update MjAssembleIT references --- .github/workflows/simian.yml | 2 +- .../java/org/eolang/maven/ContainsFiles.java | 89 ------------------- .../java/org/eolang/maven/MjAssembleIT.java | 11 +-- 3 files changed, 7 insertions(+), 95 deletions(-) delete mode 100644 eo-integration-tests/src/test/java/org/eolang/maven/ContainsFiles.java diff --git a/.github/workflows/simian.yml b/.github/workflows/simian.yml index 2da8bc4feff..417dd28206c 100644 --- a/.github/workflows/simian.yml +++ b/.github/workflows/simian.yml @@ -21,4 +21,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=15 "-excludes=**/EOsocketTest.java" "-excludes=**/gen" "-excludes=**/it" "**/*.java" "-excludes=**/ContainsFiles.java" + - run: java -jar /tmp/simian.jar -threshold=15 "-excludes=**/EOsocketTest.java" "-excludes=**/gen" "-excludes=**/it" "**/*.java" diff --git a/eo-integration-tests/src/test/java/org/eolang/maven/ContainsFiles.java b/eo-integration-tests/src/test/java/org/eolang/maven/ContainsFiles.java deleted file mode 100644 index dce319f32f0..00000000000 --- a/eo-integration-tests/src/test/java/org/eolang/maven/ContainsFiles.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com - * SPDX-License-Identifier: MIT - */ -package org.eolang.maven; - -import java.io.IOException; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; - -/** - * Asserting that path contains files matching provided globs. - * @since 0.31.0 - * @todo #4777:30min Remove {@link ContainsFiles} duplicate. - * We have exactly the same class in eo-maven-plugin module. - * We need to keep only one copy of this class and use it in both - * eo-maven-plugin and eo-integration-tests modules. - * Don't forget to remove exclusion from 'simian.yaml' as well. - */ -@SuppressWarnings({ - "JTCOP.RuleAllTestsHaveProductionClass", - "JTCOP.RuleCorrectTestName", - "JTCOP.RuleInheritanceInTests" -}) -final class ContainsFiles extends TypeSafeMatcher { - /** - * Patterns. - */ - private final String[] globs; - - /** - * Ctor. - * @param glbs Patterns - */ - ContainsFiles(final String... glbs) { - this.globs = Arrays.copyOf(glbs, glbs.length); - } - - @Override - public void describeTo(final Description description) { - description.appendText(String.format("Matching globs: %s", Arrays.toString(this.globs))); - } - - @Override - public boolean matchesSafely(final Path path) { - return Arrays.stream(this.globs) - .anyMatch( - glob -> ContainsFiles.matchesGlob( - path, - glob - ) - ); - } - - /** - * Returns whether a path matches a file pattern. - * @param item The path. - * @param glob The file pattern. - * @return True if the item matches the glob. - */ - private static boolean matchesGlob(final Path item, final String glob) { - try { - return Files.walk(item) - .anyMatch( - FileSystems - .getDefault() - .getPathMatcher( - String.format( - "glob:%s", - glob - ) - )::matches - ); - } catch (final IOException ex) { - throw new IllegalStateException( - String.format( - "Error while matching glob=`%s` for %s", - glob, - item - ), - ex - ); - } - } -} diff --git a/eo-integration-tests/src/test/java/org/eolang/maven/MjAssembleIT.java b/eo-integration-tests/src/test/java/org/eolang/maven/MjAssembleIT.java index d2d365324ac..6a91600c455 100644 --- a/eo-integration-tests/src/test/java/org/eolang/maven/MjAssembleIT.java +++ b/eo-integration-tests/src/test/java/org/eolang/maven/MjAssembleIT.java @@ -15,6 +15,7 @@ import java.nio.file.Path; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; +import org.hamcrest.io.FileMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,7 +39,7 @@ void assemblesTogether(@Mktmp final Path temp) throws IOException { f.files() .file("src/main/eo/foo/x/main.eo") .write(MjAssembleIT.program().getBytes(StandardCharsets.UTF_8)); - MjAssembleIT.appendItself(f); + MjAssembleIT.registerAssemble(f); f.exec("package"); MatcherAssert.assertThat( String.format( @@ -79,12 +80,12 @@ void assemblesNotFailWithFailOnError(@Mktmp final Path temp) throws IOException f.files() .file("src/main/eo/one/main.eo") .write(prog.getBytes(StandardCharsets.UTF_8)); - MjAssembleIT.appendItself(f); + MjAssembleIT.registerAssemble(f); f.exec("test"); MatcherAssert.assertThat( "Even if the eo program invalid we still have to parse it, but we didn't", - temp.resolve(String.format("target/eo/%s", "1-parse")).toAbsolutePath(), - new ContainsFiles("**/main.xmir") + temp.resolve("target/eo/1-parse/one/main.xmir").toAbsolutePath().toFile(), + FileMatchers.anExistingFile() ); } ); @@ -103,7 +104,7 @@ private static String program() { ); } - private static Execution appendItself(final Farea farea) throws IOException { + private static Execution registerAssemble(final Farea farea) throws IOException { return new AppendedPlugin(farea).value() .goals("register", "assemble"); }