Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.UncheckedExecutionException;
import org.apache.commons.lang.StringUtils;

import com.github.dockerjava.core.exception.GoLangFileMatchException;
Expand Down Expand Up @@ -52,6 +58,11 @@ private GoLangFileMatch() {

private static final String PATTERN_CHARS_TO_ESCAPE = "\\.[]{}()*+-?^$|";

private static final LoadingCache<String, Pattern> PATTERN_CACHE = CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.HOURS)
.maximumSize(10_000)
.build(CacheLoader.from(GoLangFileMatch::buildPattern));

public static boolean match(List<String> patterns, File file) {
return !match(patterns, file.getPath()).isEmpty();
}
Expand All @@ -74,7 +85,11 @@ public static List<String> match(List<String> patterns, String name) {
}

public static boolean match(String pattern, String name) {
return buildPattern(pattern).matcher(name).matches();
try {
return PATTERN_CACHE.get(pattern).matcher(name).matches();
} catch (ExecutionException | UncheckedExecutionException e) {
throw new GoLangFileMatchException(e.getCause().getMessage());
}
}

private static Pattern buildPattern(String pattern) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.