diff --git a/generator-engine/src/main/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGenerator.java b/generator-engine/src/main/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGenerator.java index f03ad62b..414c10c3 100644 --- a/generator-engine/src/main/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGenerator.java +++ b/generator-engine/src/main/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGenerator.java @@ -37,6 +37,9 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; import java.io.*; +import java.nio.file.FileSystems; +import java.nio.file.PathMatcher; +import java.nio.file.Paths; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -320,7 +323,17 @@ public static void synchronizeGitignoreInDirectory(PsmGeneratorParameter paramet .filter(genericParams.getDiscriminatorPredicate()) .collect(Collectors.toSet()); - ModelGenerator.synchronizeGitignoreInDirectory(genericParams, applications, (f) -> ignoredFiles.contains(f)); + ModelGenerator.synchronizeGitignoreInDirectory(genericParams, applications, getIgnoredFileMatcher(ignoredFiles)); + } + + public static Function getIgnoredFileMatcher(Collection ignoredGlobs) { + return path -> { + Boolean match = ignoredGlobs.stream().anyMatch((glob) -> { + final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + glob); + return pathMatcher.matches(Paths.get(path)); + }); + return match; + }; } public static void recalculateChecksumForDirectory(PsmGeneratorParameter.PsmGeneratorParameterBuilder builder) throws Exception { diff --git a/generator-engine/src/test/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGeneratorTest.java b/generator-engine/src/test/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGeneratorTest.java new file mode 100644 index 00000000..d2e82196 --- /dev/null +++ b/generator-engine/src/test/java/hu/blackbelt/judo/meta/psm/generator/engine/PsmGeneratorTest.java @@ -0,0 +1,27 @@ +package hu.blackbelt.judo.meta.psm.generator.engine; + +import com.google.common.collect.ImmutableSet; +import org.junit.jupiter.api.Test; + +import java.util.Collection; + +import static hu.blackbelt.judo.meta.psm.generator.engine.PsmGenerator.*; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class PsmGeneratorTest { + + @Test + void testFileIgnore() throws Exception { + Collection ignoredFiles = ImmutableSet.builder() + .add("pom.xml") + .add("**/pom.xml") + .build(); + + assertTrue(getIgnoredFileMatcher(ignoredFiles).apply("pom.xml")); + assertFalse(getIgnoredFileMatcher(ignoredFiles).apply("readme.txt")); + assertTrue(getIgnoredFileMatcher(ignoredFiles).apply("rest/pom.xml")); + assertTrue(getIgnoredFileMatcher(ignoredFiles).apply("rest/other/pom.xml")); + + } +}