View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 2.1.2,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.model;
7   
8   /**
9    * 
10   *         
11   *         The <code>&lt;dependency&gt;</code> element contains
12   * information about a dependency
13   *         of the project.
14   *         
15   *       
16   * 
17   * @version $Revision$ $Date$
18   */
19  @SuppressWarnings( "all" )
20  public class Dependency
21      implements java.io.Serializable, java.lang.Cloneable, org.apache.maven.model.InputLocationTracker
22  {
23  
24        //--------------------------/
25       //- Class/Member Variables -/
26      //--------------------------/
27  
28      /**
29       * 
30       *             
31       *             The project group that produced the dependency,
32       * e.g.
33       *             <code>org.apache.maven</code>.
34       *             
35       *           
36       */
37      private String groupId;
38  
39      /**
40       * 
41       *             
42       *             The unique id for an artifact produced by the
43       * project group, e.g.
44       *             <code>maven-artifact</code>.
45       *             
46       *           
47       */
48      private String artifactId;
49  
50      /**
51       * 
52       *             
53       *             The version of the dependency, e.g.
54       * <code>3.2.1</code>. In Maven 2, this can also be
55       *             specified as a range of versions.
56       *             
57       *           
58       */
59      private String version;
60  
61      /**
62       * 
63       *             
64       *             The type of dependency, that will be mapped to a
65       * file extension, an optional classifier, and a few other
66       * attributes.
67       *             Some examples are <code>jar</code>,
68       * <code>war</code>, <code>ejb-client</code>
69       *             and <code>test-jar</code>: see <a
70       * href="../maven-core/artifact-handlers.html">default
71       *             artifact handlers</a> for a list. New types can
72       * be defined by extensions, so this is not a complete list.
73       *             
74       *           
75       */
76      private String type = "jar";
77  
78      /**
79       * 
80       *             
81       *             The classifier of the dependency. It is appended
82       * to
83       *             the filename after the version. This allows:
84       *             <ul>
85       *             <li>referring to attached artifact, for example
86       * <code>sources</code> and <code>javadoc</code>:
87       *             see <a
88       * href="../maven-core/artifact-handlers.html">default artifact
89       * handlers</a> for a list,</li>
90       *             <li>distinguishing two artifacts
91       *             that belong to the same POM but were built
92       * differently.
93       *             For example, <code>jdk14</code> and
94       * <code>jdk15</code>.</li>
95       *             </ul>
96       *             
97       *           
98       */
99      private String classifier;
100 
101     /**
102      * 
103      *             
104      *             The scope of the dependency -
105      * <code>compile</code>, <code>runtime</code>,
106      *             <code>test</code>, <code>system</code>, and
107      * <code>provided</code>. Used to
108      *             calculate the various classpaths used for
109      * compilation, testing, and so on.
110      *             It also assists in determining which artifacts
111      * to include in a distribution of
112      *             this project. For more information, see
113      *             <a
114      * href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">the
115      *             dependency mechanism</a>. The default scope is
116      * <code>compile</code>.
117      *             
118      *           
119      */
120     private String scope;
121 
122     /**
123      * 
124      *             
125      *             FOR SYSTEM SCOPE ONLY. Note that use of this
126      * property is <b>discouraged</b>
127      *             and may be replaced in later versions. This
128      * specifies the path on the filesystem
129      *             for this dependency.
130      *             Requires an absolute path for the value, not
131      * relative.
132      *             Use a property that gives the machine specific
133      * absolute path,
134      *             e.g. <code>${java.home}</code>.
135      *             
136      *           
137      */
138     private String systemPath;
139 
140     /**
141      * Field exclusions.
142      */
143     private java.util.List<Exclusion> exclusions;
144 
145     /**
146      * 
147      *             
148      *             Indicates the dependency is optional for use of
149      * this library. While the
150      *             version of the dependency will be taken into
151      * account for dependency calculation if the
152      *             library is used elsewhere, it will not be passed
153      * on transitively. Note: While the type
154      *             of this field is <code>String</code> for
155      * technical reasons, the semantic type is actually
156      *             <code>Boolean</code>. Default value is
157      * <code>false</code>.
158      *             
159      *           
160      */
161     private String optional;
162 
163     /**
164      * Field locations.
165      */
166     private java.util.Map<Object, InputLocation> locations;
167 
168     /**
169      * Field location.
170      */
171     private InputLocation location;
172 
173     /**
174      * Field groupIdLocation.
175      */
176     private InputLocation groupIdLocation;
177 
178     /**
179      * Field artifactIdLocation.
180      */
181     private InputLocation artifactIdLocation;
182 
183     /**
184      * Field versionLocation.
185      */
186     private InputLocation versionLocation;
187 
188     /**
189      * Field typeLocation.
190      */
191     private InputLocation typeLocation;
192 
193     /**
194      * Field classifierLocation.
195      */
196     private InputLocation classifierLocation;
197 
198     /**
199      * Field scopeLocation.
200      */
201     private InputLocation scopeLocation;
202 
203     /**
204      * Field systemPathLocation.
205      */
206     private InputLocation systemPathLocation;
207 
208     /**
209      * Field exclusionsLocation.
210      */
211     private InputLocation exclusionsLocation;
212 
213     /**
214      * Field optionalLocation.
215      */
216     private InputLocation optionalLocation;
217 
218 
219       //-----------/
220      //- Methods -/
221     //-----------/
222 
223     /**
224      * Method addExclusion.
225      * 
226      * @param exclusion a exclusion object.
227      */
228     public void addExclusion( Exclusion exclusion )
229     {
230         getExclusions().add( exclusion );
231     } //-- void addExclusion( Exclusion )
232 
233     /**
234      * Method clone.
235      * 
236      * @return Dependency
237      */
238     public Dependency clone()
239     {
240         try
241         {
242             Dependency copy = (Dependency) super.clone();
243 
244             if ( this.exclusions != null )
245             {
246                 copy.exclusions = new java.util.ArrayList<Exclusion>();
247                 for ( Exclusion item : this.exclusions )
248                 {
249                     copy.exclusions.add( ( (Exclusion) item).clone() );
250                 }
251             }
252 
253             if ( copy.locations != null )
254             {
255                 copy.locations = new java.util.LinkedHashMap( copy.locations );
256             }
257 
258             return copy;
259         }
260         catch ( java.lang.Exception ex )
261         {
262             throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
263                 + " does not support clone()" ).initCause( ex );
264         }
265     } //-- Dependency clone()
266 
267     /**
268      * Get the unique id for an artifact produced by the project
269      * group, e.g.
270      *             <code>maven-artifact</code>.
271      * 
272      * @return String
273      */
274     public String getArtifactId()
275     {
276         return this.artifactId;
277     } //-- String getArtifactId()
278 
279     /**
280      * Get the classifier of the dependency. It is appended to
281      *             the filename after the version. This allows:
282      *             <ul>
283      *             <li>referring to attached artifact, for example
284      * <code>sources</code> and <code>javadoc</code>:
285      *             see <a
286      * href="../maven-core/artifact-handlers.html">default artifact
287      * handlers</a> for a list,</li>
288      *             <li>distinguishing two artifacts
289      *             that belong to the same POM but were built
290      * differently.
291      *             For example, <code>jdk14</code> and
292      * <code>jdk15</code>.</li>
293      *             </ul>
294      * 
295      * @return String
296      */
297     public String getClassifier()
298     {
299         return this.classifier;
300     } //-- String getClassifier()
301 
302     /**
303      * Method getExclusions.
304      * 
305      * @return List
306      */
307     public java.util.List<Exclusion> getExclusions()
308     {
309         if ( this.exclusions == null )
310         {
311             this.exclusions = new java.util.ArrayList<Exclusion>();
312         }
313 
314         return this.exclusions;
315     } //-- java.util.List<Exclusion> getExclusions()
316 
317     /**
318      * Get the project group that produced the dependency, e.g.
319      *             <code>org.apache.maven</code>.
320      * 
321      * @return String
322      */
323     public String getGroupId()
324     {
325         return this.groupId;
326     } //-- String getGroupId()
327 
328     /**
329      * 
330      * 
331      * @param key a key object.
332      * @return InputLocation
333      */
334     public InputLocation getLocation( Object key )
335     {
336         if ( key instanceof String )
337         {
338             switch ( ( String ) key )
339             {
340                 case "" :
341                 {
342                     return this.location;
343                 }
344                 case "groupId" :
345                 {
346                     return groupIdLocation;
347                 }
348                 case "artifactId" :
349                 {
350                     return artifactIdLocation;
351                 }
352                 case "version" :
353                 {
354                     return versionLocation;
355                 }
356                 case "type" :
357                 {
358                     return typeLocation;
359                 }
360                 case "classifier" :
361                 {
362                     return classifierLocation;
363                 }
364                 case "scope" :
365                 {
366                     return scopeLocation;
367                 }
368                 case "systemPath" :
369                 {
370                     return systemPathLocation;
371                 }
372                 case "exclusions" :
373                 {
374                     return exclusionsLocation;
375                 }
376                 case "optional" :
377                 {
378                     return optionalLocation;
379                 }
380                 default :
381                 {
382                     return getOtherLocation( key );
383                 }
384                 }
385             }
386             else
387             {
388                 return getOtherLocation( key );
389             }
390     } //-- InputLocation getLocation( Object )
391 
392     /**
393      * Get indicates the dependency is optional for use of this
394      * library. While the
395      *             version of the dependency will be taken into
396      * account for dependency calculation if the
397      *             library is used elsewhere, it will not be passed
398      * on transitively. Note: While the type
399      *             of this field is <code>String</code> for
400      * technical reasons, the semantic type is actually
401      *             <code>Boolean</code>. Default value is
402      * <code>false</code>.
403      * 
404      * @return String
405      */
406     public String getOptional()
407     {
408         return this.optional;
409     } //-- String getOptional()
410 
411     /**
412      * 
413      * 
414      * @param key a key object.
415      * @param location a location object.
416      */
417     public void setLocation( Object key, InputLocation location )
418     {
419         if ( key instanceof String )
420         {
421             switch ( ( String ) key )
422             {
423                 case "" :
424                 {
425                     this.location = location;
426                     return;
427                 }
428                 case "groupId" :
429                 {
430                     groupIdLocation = location;
431                     return;
432                 }
433                 case "artifactId" :
434                 {
435                     artifactIdLocation = location;
436                     return;
437                 }
438                 case "version" :
439                 {
440                     versionLocation = location;
441                     return;
442                 }
443                 case "type" :
444                 {
445                     typeLocation = location;
446                     return;
447                 }
448                 case "classifier" :
449                 {
450                     classifierLocation = location;
451                     return;
452                 }
453                 case "scope" :
454                 {
455                     scopeLocation = location;
456                     return;
457                 }
458                 case "systemPath" :
459                 {
460                     systemPathLocation = location;
461                     return;
462                 }
463                 case "exclusions" :
464                 {
465                     exclusionsLocation = location;
466                     return;
467                 }
468                 case "optional" :
469                 {
470                     optionalLocation = location;
471                     return;
472                 }
473                 default :
474                 {
475                     setOtherLocation( key, location );
476                     return;
477                 }
478             }
479         }
480         else
481         {
482             setOtherLocation( key, location );
483         }
484     } //-- void setLocation( Object, InputLocation )
485 
486     /**
487      * 
488      * 
489      * @param key a key object.
490      * @param location a location object.
491      */
492     public void setOtherLocation( Object key, InputLocation location )
493     {
494         if ( location != null )
495         {
496             if ( this.locations == null )
497             {
498                 this.locations = new java.util.LinkedHashMap<Object, InputLocation>();
499             }
500             this.locations.put( key, location );
501         }
502     } //-- void setOtherLocation( Object, InputLocation )
503 
504     /**
505      * 
506      * 
507      * @param key a key object.
508      * @return InputLocation
509      */
510     private InputLocation getOtherLocation( Object key )
511     {
512         return ( locations != null ) ? locations.get( key ) : null;
513     } //-- InputLocation getOtherLocation( Object )
514 
515     /**
516      * Get the scope of the dependency - <code>compile</code>,
517      * <code>runtime</code>,
518      *             <code>test</code>, <code>system</code>, and
519      * <code>provided</code>. Used to
520      *             calculate the various classpaths used for
521      * compilation, testing, and so on.
522      *             It also assists in determining which artifacts
523      * to include in a distribution of
524      *             this project. For more information, see
525      *             <a
526      * href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">the
527      *             dependency mechanism</a>. The default scope is
528      * <code>compile</code>.
529      * 
530      * @return String
531      */
532     public String getScope()
533     {
534         return this.scope;
535     } //-- String getScope()
536 
537     /**
538      * Get fOR SYSTEM SCOPE ONLY. Note that use of this property is
539      * <b>discouraged</b>
540      *             and may be replaced in later versions. This
541      * specifies the path on the filesystem
542      *             for this dependency.
543      *             Requires an absolute path for the value, not
544      * relative.
545      *             Use a property that gives the machine specific
546      * absolute path,
547      *             e.g. <code>${java.home}</code>.
548      * 
549      * @return String
550      */
551     public String getSystemPath()
552     {
553         return this.systemPath;
554     } //-- String getSystemPath()
555 
556     /**
557      * Get the type of dependency, that will be mapped to a file
558      * extension, an optional classifier, and a few other
559      * attributes.
560      *             Some examples are <code>jar</code>,
561      * <code>war</code>, <code>ejb-client</code>
562      *             and <code>test-jar</code>: see <a
563      * href="../maven-core/artifact-handlers.html">default
564      *             artifact handlers</a> for a list. New types can
565      * be defined by extensions, so this is not a complete list.
566      * 
567      * @return String
568      */
569     public String getType()
570     {
571         return this.type;
572     } //-- String getType()
573 
574     /**
575      * Get the version of the dependency, e.g. <code>3.2.1</code>.
576      * In Maven 2, this can also be
577      *             specified as a range of versions.
578      * 
579      * @return String
580      */
581     public String getVersion()
582     {
583         return this.version;
584     } //-- String getVersion()
585 
586     /**
587      * Method removeExclusion.
588      * 
589      * @param exclusion a exclusion object.
590      */
591     public void removeExclusion( Exclusion exclusion )
592     {
593         getExclusions().remove( exclusion );
594     } //-- void removeExclusion( Exclusion )
595 
596     /**
597      * Set the unique id for an artifact produced by the project
598      * group, e.g.
599      *             <code>maven-artifact</code>.
600      * 
601      * @param artifactId a artifactId object.
602      */
603     public void setArtifactId( String artifactId )
604     {
605         this.artifactId = artifactId;
606     } //-- void setArtifactId( String )
607 
608     /**
609      * Set the classifier of the dependency. It is appended to
610      *             the filename after the version. This allows:
611      *             <ul>
612      *             <li>referring to attached artifact, for example
613      * <code>sources</code> and <code>javadoc</code>:
614      *             see <a
615      * href="../maven-core/artifact-handlers.html">default artifact
616      * handlers</a> for a list,</li>
617      *             <li>distinguishing two artifacts
618      *             that belong to the same POM but were built
619      * differently.
620      *             For example, <code>jdk14</code> and
621      * <code>jdk15</code>.</li>
622      *             </ul>
623      * 
624      * @param classifier a classifier object.
625      */
626     public void setClassifier( String classifier )
627     {
628         this.classifier = classifier;
629     } //-- void setClassifier( String )
630 
631     /**
632      * Set lists a set of artifacts that should be excluded from
633      * this dependency's
634      *             artifact list when it comes to calculating
635      * transitive dependencies.
636      * 
637      * @param exclusions a exclusions object.
638      */
639     public void setExclusions( java.util.List<Exclusion> exclusions )
640     {
641         this.exclusions = exclusions;
642     } //-- void setExclusions( java.util.List )
643 
644     /**
645      * Set the project group that produced the dependency, e.g.
646      *             <code>org.apache.maven</code>.
647      * 
648      * @param groupId a groupId object.
649      */
650     public void setGroupId( String groupId )
651     {
652         this.groupId = groupId;
653     } //-- void setGroupId( String )
654 
655     /**
656      * Set indicates the dependency is optional for use of this
657      * library. While the
658      *             version of the dependency will be taken into
659      * account for dependency calculation if the
660      *             library is used elsewhere, it will not be passed
661      * on transitively. Note: While the type
662      *             of this field is <code>String</code> for
663      * technical reasons, the semantic type is actually
664      *             <code>Boolean</code>. Default value is
665      * <code>false</code>.
666      * 
667      * @param optional a optional object.
668      */
669     public void setOptional( String optional )
670     {
671         this.optional = optional;
672     } //-- void setOptional( String )
673 
674     /**
675      * Set the scope of the dependency - <code>compile</code>,
676      * <code>runtime</code>,
677      *             <code>test</code>, <code>system</code>, and
678      * <code>provided</code>. Used to
679      *             calculate the various classpaths used for
680      * compilation, testing, and so on.
681      *             It also assists in determining which artifacts
682      * to include in a distribution of
683      *             this project. For more information, see
684      *             <a
685      * href="https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html">the
686      *             dependency mechanism</a>. The default scope is
687      * <code>compile</code>.
688      * 
689      * @param scope a scope object.
690      */
691     public void setScope( String scope )
692     {
693         this.scope = scope;
694     } //-- void setScope( String )
695 
696     /**
697      * Set fOR SYSTEM SCOPE ONLY. Note that use of this property is
698      * <b>discouraged</b>
699      *             and may be replaced in later versions. This
700      * specifies the path on the filesystem
701      *             for this dependency.
702      *             Requires an absolute path for the value, not
703      * relative.
704      *             Use a property that gives the machine specific
705      * absolute path,
706      *             e.g. <code>${java.home}</code>.
707      * 
708      * @param systemPath a systemPath object.
709      */
710     public void setSystemPath( String systemPath )
711     {
712         this.systemPath = systemPath;
713     } //-- void setSystemPath( String )
714 
715     /**
716      * Set the type of dependency, that will be mapped to a file
717      * extension, an optional classifier, and a few other
718      * attributes.
719      *             Some examples are <code>jar</code>,
720      * <code>war</code>, <code>ejb-client</code>
721      *             and <code>test-jar</code>: see <a
722      * href="../maven-core/artifact-handlers.html">default
723      *             artifact handlers</a> for a list. New types can
724      * be defined by extensions, so this is not a complete list.
725      * 
726      * @param type a type object.
727      */
728     public void setType( String type )
729     {
730         this.type = type;
731     } //-- void setType( String )
732 
733     /**
734      * Set the version of the dependency, e.g. <code>3.2.1</code>.
735      * In Maven 2, this can also be
736      *             specified as a range of versions.
737      * 
738      * @param version a version object.
739      */
740     public void setVersion( String version )
741     {
742         this.version = version;
743     } //-- void setVersion( String )
744 
745     
746             
747     public boolean isOptional()
748     {
749         return ( optional != null ) ? Boolean.parseBoolean( optional ) : false;
750     }
751 
752     public void setOptional( boolean optional )
753     {
754         this.optional = String.valueOf( optional );
755     }
756 
757     /**
758      * @see java.lang.Object#toString()
759      */
760     public String toString()
761     {
762         return "Dependency {groupId=" + groupId + ", artifactId=" + artifactId + ", version=" + version + ", type=" + type + "}";
763     }
764             
765           
766     
767             
768     private String managementKey;
769 
770     /**
771      * @return the management key as <code>groupId:artifactId:type</code>
772      */
773     public String getManagementKey()
774     {
775         if ( managementKey == null )
776         {
777             managementKey = groupId + ":" + artifactId + ":" + type + ( classifier != null ? ":" + classifier : "" );
778         }
779         return managementKey;
780     }
781 
782     /**
783      * Clears the management key in case one field has been modified.
784      */
785     public void clearManagementKey()
786     {
787         managementKey = null;
788     }
789             
790           
791 }