1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.graph.transformer;
20
21 import org.eclipse.aether.RepositoryException;
22 import org.eclipse.aether.collection.DependencyGraphTransformationContext;
23 import org.eclipse.aether.collection.DependencyGraphTransformer;
24 import org.eclipse.aether.graph.DependencyNode;
25
26 import static java.util.Objects.requireNonNull;
27
28
29
30
31 public final class ChainedDependencyGraphTransformer implements DependencyGraphTransformer {
32
33 private final DependencyGraphTransformer[] transformers;
34
35
36
37
38
39
40 public ChainedDependencyGraphTransformer(DependencyGraphTransformer... transformers) {
41 if (transformers == null) {
42 this.transformers = new DependencyGraphTransformer[0];
43 } else {
44 this.transformers = transformers;
45 }
46 }
47
48
49
50
51
52
53
54
55
56 public static DependencyGraphTransformer newInstance(
57 DependencyGraphTransformer transformer1, DependencyGraphTransformer transformer2) {
58 if (transformer1 == null) {
59 return transformer2;
60 } else if (transformer2 == null) {
61 return transformer1;
62 }
63 return new ChainedDependencyGraphTransformer(transformer1, transformer2);
64 }
65
66 @Override
67 public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context)
68 throws RepositoryException {
69 requireNonNull(node, "node cannot be null");
70 requireNonNull(context, "context cannot be null");
71 for (DependencyGraphTransformer transformer : transformers) {
72 node = transformer.transformGraph(node, context);
73 }
74 return node;
75 }
76 }