netflix.nebula.dependency.recommender.provider.FuzzyVersionResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nebula-dependency-recommender Show documentation
Show all versions of nebula-dependency-recommender Show documentation
Allows projects to leave off version numbers in dependencies section and have versions recommended by other sources
package netflix.nebula.dependency.recommender.provider;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public abstract class FuzzyVersionResolver {
private Map globs;
abstract protected Collection propertyNames();
abstract protected String propertyValue(String name);
private String resolveVersion(String value) {
if(value == null) return null;
if(!value.startsWith("$")) return value;
return resolveVersion(versionOf(value.substring(1)));
}
public String versionOf(String key) {
String version = propertyValue(key);
if(version != null) return resolveVersion(version);
if(globs == null) {
// initialize glob cache
globs = new HashMap<>();
for (String name : propertyNames()) {
if(name.contains("*")) {
globs.put(Pattern.compile(name.replaceAll("\\*", ".*?")), propertyValue(name));
}
}
}
for (Map.Entry glob: globs.entrySet())
if(glob.getKey().matcher(key).matches())
return resolveVersion(glob.getValue());
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy