-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequentialDependencyGraphBuilder.java
More file actions
57 lines (45 loc) · 2.25 KB
/
SequentialDependencyGraphBuilder.java
File metadata and controls
57 lines (45 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package blue.contract.packager.graphbuilder;
import blue.contract.packager.model.DependencyGraph;
import blue.contract.packager.model.DirectoryNode;
import blue.language.model.Node;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class SequentialDependencyGraphBuilder implements DependencyGraphBuilder {
private final List<DependencyGraphBuilder> builders;
public SequentialDependencyGraphBuilder(List<DependencyGraphBuilder> builders) {
this.builders = builders;
}
@Override
public DependencyGraph buildDependencyGraph(String rootDir) throws IOException {
DependencyGraph combinedGraph = new DependencyGraph();
for (DependencyGraphBuilder builder : builders) {
DependencyGraph graph = builder.buildDependencyGraph(rootDir);
mergeGraphs(combinedGraph, graph);
}
return combinedGraph;
}
private void mergeGraphs(DependencyGraph target, DependencyGraph source) {
for (Map.Entry<String, Map<String, DirectoryNode>> typeEntry : source.getDirectories().entrySet()) {
String typeName = typeEntry.getKey();
Map<String, DirectoryNode> sourceVersions = typeEntry.getValue();
for (Map.Entry<String, DirectoryNode> versionEntry : sourceVersions.entrySet()) {
String version = versionEntry.getKey();
DirectoryNode sourceDir = versionEntry.getValue();
// Check if this type+version combination already exists in the target
Map<String, DirectoryNode> targetVersions = target.getDirectories().get(typeName);
if (targetVersions != null && targetVersions.containsKey(version)) {
throw new IllegalStateException(
String.format("Directory collision detected: %s version %s", typeName, version)
);
}
// Add the directory with its dependency
target.addDirectory(typeName, version, sourceDir.getDependency());
// Add all nodes from the source directory
for (Node node : sourceDir.getNodes().values()) {
target.addNode(typeName, version, node);
}
}
}
}
}