1
2
3
4
5 package org.apache.maven.api.toolchain;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Objects;
15 import java.util.Optional;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19 import org.apache.maven.api.annotations.Experimental;
20 import org.apache.maven.api.annotations.Generated;
21 import org.apache.maven.api.annotations.Immutable;
22 import org.apache.maven.api.annotations.Nonnull;
23 import org.apache.maven.api.annotations.NotThreadSafe;
24 import org.apache.maven.api.annotations.ThreadSafe;
25
26
27
28
29
30 @Experimental
31 @Generated @ThreadSafe @Immutable
32 public class PersistedToolchains
33 extends TrackableBase
34 implements Serializable, InputLocationTracker
35 {
36 final String namespaceUri;
37 final String modelEncoding;
38
39
40
41 final List<ToolchainModel> toolchains;
42
43
44
45
46
47 protected PersistedToolchains(Builder builder) {
48 super(builder);
49 this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
50 this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding : "UTF-8");
51 this.toolchains = ImmutableCollections.copy(builder.toolchains != null ? builder.toolchains : (builder.base != null ? builder.base.toolchains : null));
52 }
53
54 public String getNamespaceUri() {
55 return namespaceUri;
56 }
57
58 public String getModelEncoding() {
59 return modelEncoding;
60 }
61
62
63
64
65
66
67 @Nonnull
68 public List<ToolchainModel> getToolchains() {
69 return this.toolchains;
70 }
71
72
73
74
75
76
77 @Nonnull
78 public Builder with() {
79 return newBuilder(this);
80 }
81
82
83
84
85
86
87 @Nonnull
88 public PersistedToolchains withToolchains(Collection<ToolchainModel> toolchains) {
89 return newBuilder(this, true).toolchains(toolchains).build();
90 }
91
92
93
94
95
96
97
98
99 @Nonnull
100 public static PersistedToolchains newInstance() {
101 return newInstance(true);
102 }
103
104
105
106
107
108
109
110
111 @Nonnull
112 public static PersistedToolchains newInstance(boolean withDefaults) {
113 return newBuilder(withDefaults).build();
114 }
115
116
117
118
119
120
121
122
123 @Nonnull
124 public static Builder newBuilder() {
125 return newBuilder(true);
126 }
127
128
129
130
131
132
133
134 @Nonnull
135 public static Builder newBuilder(boolean withDefaults) {
136 return new Builder(withDefaults);
137 }
138
139
140
141
142
143
144
145
146 @Nonnull
147 public static Builder newBuilder(PersistedToolchains from) {
148 return newBuilder(from, false);
149 }
150
151
152
153
154
155
156
157
158 @Nonnull
159 public static Builder newBuilder(PersistedToolchains from, boolean forceCopy) {
160 return new Builder(from, forceCopy);
161 }
162
163
164
165
166
167
168 @NotThreadSafe
169 public static class Builder
170 extends TrackableBase.Builder
171 {
172 PersistedToolchains base;
173 String namespaceUri;
174 String modelEncoding;
175 Collection<ToolchainModel> toolchains;
176
177 protected Builder(boolean withDefaults) {
178 super(withDefaults);
179 if (withDefaults) {
180 }
181 }
182
183 protected Builder(PersistedToolchains base, boolean forceCopy) {
184 super(base, forceCopy);
185 this.namespaceUri = base.namespaceUri;
186 this.modelEncoding = base.modelEncoding;
187 if (forceCopy) {
188 this.toolchains = base.toolchains;
189 this.locations = base.locations;
190 this.importedFrom = base.importedFrom;
191 } else {
192 this.base = base;
193 }
194 }
195
196 @Nonnull
197 public Builder namespaceUri(String namespaceUri) {
198 this.namespaceUri = namespaceUri;
199 return this;
200 }
201
202 @Nonnull
203 public Builder modelEncoding(String modelEncoding) {
204 this.modelEncoding = modelEncoding;
205 return this;
206 }
207
208 @Nonnull
209 public Builder toolchains(Collection<ToolchainModel> toolchains) {
210 this.toolchains = toolchains;
211 return this;
212 }
213
214
215 @Nonnull
216 public Builder location(Object key, InputLocation location) {
217 if (location != null) {
218 if (!(this.locations instanceof HashMap)) {
219 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
220 }
221 this.locations.put(key, location);
222 }
223 return this;
224 }
225
226 @Nonnull
227 public Builder importedFrom(InputLocation importedFrom) {
228 this.importedFrom = importedFrom;
229 return this;
230 }
231
232 @Nonnull
233 public PersistedToolchains build() {
234
235 if (base != null
236 && (toolchains == null || toolchains == base.toolchains)
237 ) {
238 return base;
239 }
240 return new PersistedToolchains(this);
241 }
242
243 }
244
245 }