All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.vyarus.gradle.plugin.animalsniffer.util.ExcludeFilePatternSpec.groovy Maven / Gradle / Ivy

package ru.vyarus.gradle.plugin.animalsniffer.util

import org.gradle.api.specs.Spec

import java.util.regex.Pattern

/**
 * Spec excludes files matching provided pattern. Accept regexp as input.
 * Input pattern could contain '*' (for simpler pattern definition), which will be replaced with '.+'.
 * 

* NOTE: as it assumed to be used with classpath only, file extension is not checked! * * @author Vyacheslav Rusakov * @since 18.07.2017 */ class ExcludeFilePatternSpec implements Spec { private final Pattern pattern ExcludeFilePatternSpec(Collection desc) { this.pattern = buildPattern(desc) } @Override boolean isSatisfiedBy(File element) { String name = element.name[0..element.name.lastIndexOf('.') - 1] return pattern == null || !pattern.matcher(name).matches() } private static Pattern buildPattern(Collection desc) { if (!desc) { return null } List res = desc.collect { "(${it.replace('*', '.+')})" } return Pattern.compile(res.join('|')) } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy