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