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