1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.api.model;
20
21 import java.io.Serializable;
22 import java.util.Collection;
23 import java.util.List;
24 import java.util.Objects;
25 import java.util.stream.Collectors;
26 import java.util.stream.Stream;
27
28
29
30
31
32
33
34
35
36
37 public class InputSource implements Serializable {
38
39 private final String modelId;
40 private final String location;
41 private final List<InputSource> inputs;
42 private final InputLocation importedFrom;
43
44 public InputSource(String modelId, String location) {
45 this(modelId, location, null);
46 }
47
48 public InputSource(String modelId, String location, InputLocation importedFrom) {
49 this.modelId = modelId;
50 this.location = location;
51 this.inputs = null;
52 this.importedFrom = importedFrom;
53 }
54
55 public InputSource(Collection<InputSource> inputs) {
56 this.modelId = null;
57 this.location = null;
58 this.inputs = ImmutableCollections.copy(inputs);
59 this.importedFrom = null;
60 }
61
62
63
64
65
66
67 public String getLocation() {
68 return this.location;
69 }
70
71
72
73
74
75
76 public String getModelId() {
77 return this.modelId;
78 }
79
80
81
82
83
84
85
86
87 public InputLocation getImportedFrom() {
88 return importedFrom;
89 }
90
91 @Override
92 public boolean equals(Object o) {
93 if (this == o) {
94 return true;
95 }
96 if (o == null || getClass() != o.getClass()) {
97 return false;
98 }
99 InputSource that = (InputSource) o;
100 return Objects.equals(modelId, that.modelId)
101 && Objects.equals(location, that.location)
102 && Objects.equals(inputs, that.inputs);
103 }
104
105 @Override
106 public int hashCode() {
107 return Objects.hash(modelId, location, inputs);
108 }
109
110 Stream<InputSource> sources() {
111 return inputs != null ? inputs.stream() : Stream.of(this);
112 }
113
114 @Override
115 public String toString() {
116 if (inputs != null) {
117 return inputs.stream().map(InputSource::toString).collect(Collectors.joining(", ", "merged[", "]"));
118 }
119 return getModelId() + " " + getLocation();
120 }
121
122 public static InputSource merge(InputSource src1, InputSource src2) {
123 return new InputSource(Stream.concat(src1.sources(), src2.sources()).collect(Collectors.toSet()));
124 }
125 }