1
2
3
4 package org.apache.maven.model;
5
6 import java.io.Serializable;
7 import java.util.AbstractList;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import java.util.Objects;
14 import java.util.stream.Collectors;
15 import java.util.stream.Stream;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Nonnull;
18
19 @Generated
20 public class Dependency
21 extends BaseObject
22 {
23
24 public Dependency()
25 {
26 this( org.apache.maven.api.model.Dependency.newInstance() );
27 }
28
29 public Dependency( org.apache.maven.api.model.Dependency delegate )
30 {
31 this( delegate, null );
32 }
33
34 public Dependency( org.apache.maven.api.model.Dependency delegate, BaseObject parent )
35 {
36 super( delegate, parent );
37 }
38
39 public Dependency clone()
40 {
41 return new Dependency( getDelegate() );
42 }
43
44 public org.apache.maven.api.model.Dependency getDelegate()
45 {
46 return ( org.apache.maven.api.model.Dependency ) super.getDelegate();
47 }
48
49 public String getGroupId()
50 {
51 return getDelegate().getGroupId();
52 }
53
54 public void setGroupId( String groupId )
55 {
56 if ( !Objects.equals( groupId, getDelegate().getGroupId() ) )
57 {
58 update( getDelegate().withGroupId( groupId ) );
59 }
60 }
61
62 public String getArtifactId()
63 {
64 return getDelegate().getArtifactId();
65 }
66
67 public void setArtifactId( String artifactId )
68 {
69 if ( !Objects.equals( artifactId, getDelegate().getArtifactId() ) )
70 {
71 update( getDelegate().withArtifactId( artifactId ) );
72 }
73 }
74
75 public String getVersion()
76 {
77 return getDelegate().getVersion();
78 }
79
80 public void setVersion( String version )
81 {
82 if ( !Objects.equals( version, getDelegate().getVersion() ) )
83 {
84 update( getDelegate().withVersion( version ) );
85 }
86 }
87
88 public String getType()
89 {
90 return getDelegate().getType();
91 }
92
93 public void setType( String type )
94 {
95 if ( !Objects.equals( type, getDelegate().getType() ) )
96 {
97 update( getDelegate().withType( type ) );
98 }
99 }
100
101 public String getClassifier()
102 {
103 return getDelegate().getClassifier();
104 }
105
106 public void setClassifier( String classifier )
107 {
108 if ( !Objects.equals( classifier, getDelegate().getClassifier() ) )
109 {
110 update( getDelegate().withClassifier( classifier ) );
111 }
112 }
113
114 public String getScope()
115 {
116 return getDelegate().getScope();
117 }
118
119 public void setScope( String scope )
120 {
121 if ( !Objects.equals( scope, getDelegate().getScope() ) )
122 {
123 update( getDelegate().withScope( scope ) );
124 }
125 }
126
127 public String getSystemPath()
128 {
129 return getDelegate().getSystemPath();
130 }
131
132 public void setSystemPath( String systemPath )
133 {
134 if ( !Objects.equals( systemPath, getDelegate().getSystemPath() ) )
135 {
136 update( getDelegate().withSystemPath( systemPath ) );
137 }
138 }
139
140 @Nonnull
141 public List<Exclusion> getExclusions()
142 {
143 return new WrapperList<Exclusion, org.apache.maven.api.model.Exclusion>(
144 () -> getDelegate().getExclusions(), l -> update( getDelegate().withExclusions( l ) ),
145 d -> new Exclusion( d, this ), Exclusion::getDelegate );
146 }
147
148 public void setExclusions( List<Exclusion> exclusions )
149 {
150 if ( !Objects.equals( exclusions, getDelegate().getExclusions() ) )
151 {
152 update( getDelegate().withExclusions(
153 exclusions.stream().map( c -> c.getDelegate() ).collect( Collectors.toList() ) ) );
154 exclusions.forEach( e -> e.childrenTracking = this::replace );
155 }
156 }
157
158 public void addExclusion( Exclusion exclusion )
159 {
160 update( getDelegate().withExclusions(
161 Stream.concat( getDelegate().getExclusions().stream(), Stream.of( exclusion.getDelegate() ) )
162 .collect( Collectors.toList() ) ) );
163 exclusion.childrenTracking = this::replace;
164 }
165
166 public void removeExclusion( Exclusion exclusion )
167 {
168 update( getDelegate().withExclusions(
169 getDelegate().getExclusions().stream()
170 .filter( e -> !Objects.equals( e, exclusion ) )
171 .collect( Collectors.toList() ) ) );
172 exclusion.childrenTracking = null;
173 }
174
175 public String getOptional()
176 {
177 return getDelegate().getOptional();
178 }
179
180 public void setOptional( String optional )
181 {
182 if ( !Objects.equals( optional, getDelegate().getOptional() ) )
183 {
184 update( getDelegate().withOptional( optional ) );
185 }
186 }
187
188 public InputLocation getLocation( Object key )
189 {
190 org.apache.maven.api.model.InputLocation loc = getDelegate().getLocation( key );
191 return loc != null ? new InputLocation( loc ) : null;
192 }
193
194 public void setLocation( Object key, InputLocation location )
195 {
196 update( org.apache.maven.api.model.Dependency.newBuilder( getDelegate(), true )
197 .location( key, location.toApiLocation() ).build() );
198 }
199
200 protected boolean replace( Object oldDelegate, Object newDelegate )
201 {
202 if ( super.replace( oldDelegate, newDelegate ) )
203 {
204 return true;
205 }
206 if ( getDelegate().getExclusions().contains( oldDelegate ) )
207 {
208 List<org.apache.maven.api.model.Exclusion> list = new ArrayList<>( getDelegate().getExclusions() );
209 list.replaceAll( d -> d == oldDelegate ? ( org.apache.maven.api.model.Exclusion ) newDelegate : d );
210 update( getDelegate().withExclusions( list ) );
211 return true;
212 }
213 return false;
214 }
215
216 public static List<org.apache.maven.api.model.Dependency> dependencyToApiV4( List<Dependency> list )
217 {
218 return list != null ? new WrapperList<>( list, Dependency::getDelegate, Dependency::new ) : null;
219 }
220
221 public static List<Dependency> dependencyToApiV3( List<org.apache.maven.api.model.Dependency> list )
222 {
223 return list != null ? new WrapperList<>( list, Dependency::new, Dependency::getDelegate ) : null;
224 }
225
226
227
228 public boolean isOptional()
229 {
230 return ( getOptional() != null ) ? Boolean.parseBoolean( getOptional() ) : false;
231 }
232
233
234
235
236
237 public void setOptional( boolean optional )
238 {
239 setOptional( String.valueOf( optional ) );
240 }
241
242
243
244
245
246
247
248
249 public String toString()
250 {
251 return "Dependency {groupId=" + getGroupId() + ", artifactId=" + getArtifactId() + ", version=" + getVersion() + ", type=" + getType() + "}";
252 }
253
254
255
256
257 private volatile String managementKey;
258
259
260
261
262 public String getManagementKey()
263 {
264 if ( managementKey == null )
265 {
266 managementKey = getGroupId() + ":" + getArtifactId() + ":" + getType() + ( getClassifier() != null ? ":" + getClassifier() : "" );
267 }
268 return managementKey;
269 }
270
271
272 }