Skip to content

Commit

Permalink
JNG-5937 Generator git ignore synchronizer glob ignore (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany authored Sep 24, 2024
1 parent 27aa228 commit 116febb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Boolean> getIgnoredFileMatcher(Collection<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> ignoredFiles = ImmutableSet.<String>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"));

}
}

0 comments on commit 116febb

Please sign in to comment.