32 lines
1.1 KiB
Java
32 lines
1.1 KiB
Java
package io.gitlab.jfronny.respackopts.filters.util;
|
|
|
|
import io.gitlab.jfronny.respackopts.Respackopts;
|
|
|
|
import java.util.*;
|
|
|
|
public class FileDependencyTracker {
|
|
private final String pack;
|
|
private final Map<String, Set<String>> dependencies = new HashMap<>();
|
|
private final Map<String, Set<String>> dependents = new HashMap<>();
|
|
private final Set<String> reportedRecursions = new HashSet<>();
|
|
|
|
public FileDependencyTracker(String pack) {
|
|
this.pack = pack;
|
|
}
|
|
|
|
public void addDependency(String to, String on) {
|
|
if (to.equals(on)) {
|
|
if (reportedRecursions.add(to)) Respackopts.LOGGER.warn("Discovered recursive dependency in " + pack + "! If you get a StackOverflowException, please validate your fallbacks for " + to);
|
|
return;
|
|
}
|
|
gs(dependencies, to).add(on);
|
|
gs(dependents, on).add(to);
|
|
gs(dependents, to).forEach(dp -> addDependency(dp, on));
|
|
gs(dependencies, on).forEach(dp -> addDependency(to, dp));
|
|
}
|
|
|
|
private Set<String> gs(Map<String, Set<String>> map, String key) {
|
|
return map.computeIfAbsent(key, _1 -> new HashSet<>());
|
|
}
|
|
}
|