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