View Javadoc

1   /*
2    * $Id$
3    */
4   
5   package org.apache.maven.model;
6   
7     //---------------------------------/
8    //- Imported classes and packages -/
9   //---------------------------------/
10  
11  import java.util.Date;
12  
13  /**
14   * This element describes all of the classpath resources associated
15   * with a project
16   *         or unit tests.
17   * 
18   * @version $Revision$ $Date$
19   */
20  public class Resource extends FileSet 
21  implements java.io.Serializable
22  {
23  
24  
25        //--------------------------/
26       //- Class/Member Variables -/
27      //--------------------------/
28  
29      /**
30       * 
31       *             
32       *             Describe the resource target path. The path is
33       * relative to the target/classes
34       *             directory (i.e.
35       * <code>${project.build.outputDirectory}</code>).
36       *             For example, if you want that resource to appear
37       * in a specific package
38       *             (<code>org.apache.maven.messages</code>), you
39       * must specify this
40       *             element with this value:
41       * <code>org/apache/maven/messages</code>.
42       *             This is not required if you simply put the
43       * resources in that directory
44       *             structure at the source, however.
45       *             
46       *           
47       */
48      private String targetPath;
49  
50      /**
51       * 
52       *             
53       *             Whether resources are filtered to replace tokens
54       * with parameterised values or not.
55       *             The values are taken from the
56       * <code>properties</code> element and from the
57       *             properties in the files listed in the
58       * <code>filters</code> element.
59       *             
60       *           
61       */
62      private boolean filtering = false;
63  
64      /**
65       * 
66       *             
67       *             FOR INTERNAL USE ONLY. This is a unique
68       * identifier assigned to each
69       *             resource to allow Maven to merge changes to this
70       * resource that take
71       *             place during the execution of a plugin. This
72       * field must be managed
73       *             by the generated parser and formatter classes in
74       * order to allow it
75       *             to survive model interpolation.
76       *             
77       *           
78       */
79      private String mergeId;
80  
81  
82        //-----------/
83       //- Methods -/
84      //-----------/
85  
86      /**
87       * Get 
88       *             
89       *             FOR INTERNAL USE ONLY. This is a unique
90       * identifier assigned to each
91       *             resource to allow Maven to merge changes to this
92       * resource that take
93       *             place during the execution of a plugin. This
94       * field must be managed
95       *             by the generated parser and formatter classes in
96       * order to allow it
97       *             to survive model interpolation.
98       *             
99       *           
100      * 
101      * @return String
102      */
103     public String getMergeId()
104     {
105         return this.mergeId;
106     } //-- String getMergeId() 
107 
108     /**
109      * Get 
110      *             
111      *             Describe the resource target path. The path is
112      * relative to the target/classes
113      *             directory (i.e.
114      * <code>${project.build.outputDirectory}</code>).
115      *             For example, if you want that resource to appear
116      * in a specific package
117      *             (<code>org.apache.maven.messages</code>), you
118      * must specify this
119      *             element with this value:
120      * <code>org/apache/maven/messages</code>.
121      *             This is not required if you simply put the
122      * resources in that directory
123      *             structure at the source, however.
124      *             
125      *           
126      * 
127      * @return String
128      */
129     public String getTargetPath()
130     {
131         return this.targetPath;
132     } //-- String getTargetPath() 
133 
134     /**
135      * Get 
136      *             
137      *             Whether resources are filtered to replace tokens
138      * with parameterised values or not.
139      *             The values are taken from the
140      * <code>properties</code> element and from the
141      *             properties in the files listed in the
142      * <code>filters</code> element.
143      *             
144      *           
145      * 
146      * @return boolean
147      */
148     public boolean isFiltering()
149     {
150         return this.filtering;
151     } //-- boolean isFiltering() 
152 
153     /**
154      * Set 
155      *             
156      *             Whether resources are filtered to replace tokens
157      * with parameterised values or not.
158      *             The values are taken from the
159      * <code>properties</code> element and from the
160      *             properties in the files listed in the
161      * <code>filters</code> element.
162      *             
163      *           
164      * 
165      * @param filtering
166      */
167     public void setFiltering( boolean filtering )
168     {
169         this.filtering = filtering;
170     } //-- void setFiltering( boolean ) 
171 
172     /**
173      * Set 
174      *             
175      *             FOR INTERNAL USE ONLY. This is a unique
176      * identifier assigned to each
177      *             resource to allow Maven to merge changes to this
178      * resource that take
179      *             place during the execution of a plugin. This
180      * field must be managed
181      *             by the generated parser and formatter classes in
182      * order to allow it
183      *             to survive model interpolation.
184      *             
185      *           
186      * 
187      * @param mergeId
188      */
189     public void setMergeId( String mergeId )
190     {
191         this.mergeId = mergeId;
192     } //-- void setMergeId( String ) 
193 
194     /**
195      * Set 
196      *             
197      *             Describe the resource target path. The path is
198      * relative to the target/classes
199      *             directory (i.e.
200      * <code>${project.build.outputDirectory}</code>).
201      *             For example, if you want that resource to appear
202      * in a specific package
203      *             (<code>org.apache.maven.messages</code>), you
204      * must specify this
205      *             element with this value:
206      * <code>org/apache/maven/messages</code>.
207      *             This is not required if you simply put the
208      * resources in that directory
209      *             structure at the source, however.
210      *             
211      *           
212      * 
213      * @param targetPath
214      */
215     public void setTargetPath( String targetPath )
216     {
217         this.targetPath = targetPath;
218     } //-- void setTargetPath( String ) 
219 
220 
221             
222     private static int mergeIdCounter = 0;
223 
224     public void initMergeId()
225     {
226         if ( getMergeId() == null )
227         {
228             setMergeId( "resource-" + (mergeIdCounter++) );
229         }
230     }
231 
232     /**
233      * @see java.lang.Object#toString()
234      */
235     public String toString()
236     {
237         return "Resource {targetPath: " + getTargetPath() + ", filtering: " + isFiltering() + ", " + super.toString() + "}";
238     }
239             
240           
241     private String modelEncoding = "UTF-8";
242 
243     /**
244      * Set an encoding used for reading/writing the model.
245      *
246      * @param modelEncoding the encoding used when reading/writing the model.
247      */
248     public void setModelEncoding( String modelEncoding )
249     {
250         this.modelEncoding = modelEncoding;
251     }
252 
253     /**
254      * @return the current encoding used when reading/writing this model.
255      */
256     public String getModelEncoding()
257     {
258         return modelEncoding;
259     }
260 }