1
2
3
4
5 package org.apache.maven.api.settings;
6
7 import java.io.Serializable;
8 import java.util.Collections;
9 import java.util.HashMap;
10 import java.util.Map;
11 import org.apache.maven.api.annotations.Experimental;
12 import org.apache.maven.api.annotations.Generated;
13 import org.apache.maven.api.annotations.Immutable;
14 import org.apache.maven.api.annotations.Nonnull;
15 import org.apache.maven.api.annotations.NotThreadSafe;
16 import org.apache.maven.api.annotations.ThreadSafe;
17
18
19
20
21
22 @Experimental
23 @Generated @ThreadSafe @Immutable
24 public class TrackableBase
25 implements Serializable, InputLocationTracker
26 {
27
28 final Map<Object, InputLocation> locations;
29
30
31
32
33
34 TrackableBase(
35 Map<Object, InputLocation> locations
36 ) {
37 this.locations = ImmutableCollections.copy(locations);
38 }
39
40
41
42
43 public InputLocation getLocation(Object key) {
44 return locations != null ? locations.get(key) : null;
45 }
46
47
48
49
50
51
52 @Nonnull
53 public Builder with() {
54 return newBuilder(this);
55 }
56
57
58
59
60
61
62
63
64 @Nonnull
65 public static TrackableBase newInstance() {
66 return newInstance(true);
67 }
68
69
70
71
72
73
74
75
76 @Nonnull
77 public static TrackableBase newInstance(boolean withDefaults) {
78 return newBuilder(withDefaults).build();
79 }
80
81
82
83
84
85
86
87
88 @Nonnull
89 public static Builder newBuilder() {
90 return newBuilder(true);
91 }
92
93
94
95
96
97
98
99 @Nonnull
100 public static Builder newBuilder(boolean withDefaults) {
101 return new Builder(withDefaults);
102 }
103
104
105
106
107
108
109
110
111 @Nonnull
112 public static Builder newBuilder(TrackableBase from) {
113 return newBuilder(from, false);
114 }
115
116
117
118
119
120
121
122
123 @Nonnull
124 public static Builder newBuilder(TrackableBase from, boolean forceCopy) {
125 return new Builder(from, forceCopy);
126 }
127
128
129
130
131
132
133 @NotThreadSafe
134 public static class Builder
135 {
136 TrackableBase base;
137 Map<Object, InputLocation> locations;
138
139 Builder(boolean withDefaults) {
140 if (withDefaults) {
141 }
142 }
143
144 Builder(TrackableBase base, boolean forceCopy) {
145 if (forceCopy) {
146 this.locations = base.locations;
147 } else {
148 this.base = base;
149 }
150 }
151
152
153 @Nonnull
154 public Builder location(Object key, InputLocation location) {
155 if (location != null) {
156 if (!(this.locations instanceof HashMap)) {
157 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
158 }
159 this.locations.put(key, location);
160 }
161 return this;
162 }
163
164 @Nonnull
165 public TrackableBase build() {
166 if (base != null
167 ) {
168 return base;
169 }
170 Map<Object, InputLocation> newlocs = this.locations != null ? this.locations : Collections.emptyMap();
171 Map<Object, InputLocation> oldlocs = this.base != null && this.base.locations != null ? this.base.locations : Collections.emptyMap();
172 Map<Object, InputLocation> locations = new HashMap<>();
173 locations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get(""));
174 return new TrackableBase(
175 locations
176 );
177 }
178 }
179
180
181
182 public static final String USER_LEVEL = "user-level";
183 public static final String PROJECT_LEVEL = "project-level";
184 public static final String GLOBAL_LEVEL = "global-level";
185
186 private String sourceLevel = USER_LEVEL;
187 private boolean sourceLevelSet = false;
188
189 public void setSourceLevel( String sourceLevel )
190 {
191 if ( sourceLevelSet )
192 {
193 throw new IllegalStateException( "Cannot reset sourceLevel attribute; it is already set to: " + sourceLevel );
194 }
195 else if ( !( USER_LEVEL.equals( sourceLevel ) || PROJECT_LEVEL.equals( sourceLevel ) || GLOBAL_LEVEL.equals( sourceLevel ) ) )
196 {
197 throw new IllegalArgumentException( "sourceLevel must be one of: {" + USER_LEVEL + "," + PROJECT_LEVEL + "," + GLOBAL_LEVEL + "}" );
198 }
199 else
200 {
201 this.sourceLevel = sourceLevel;
202 this.sourceLevelSet = true;
203 }
204 }
205
206 public String getSourceLevel()
207 {
208 return sourceLevel;
209 }
210
211
212 }