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