View Javadoc
1   package org.apache.maven.archiver;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.LinkedHashMap;
24  import java.util.LinkedList;
25  import java.util.List;
26  import java.util.Map;
27  
28  /**
29   * Capture common archive configuration.
30   *
31   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
32   */
33  // TODO Is this general enough to be in Plexus Archiver?
34  public class MavenArchiveConfiguration
35  {
36      private boolean compress = true;
37  
38      private boolean recompressAddedZips = true;
39  
40      private boolean index;
41  
42      private boolean addMavenDescriptor = true;
43  
44      private File manifestFile;
45  
46      //TODO: Rename this attribute to manifestConfiguration;
47      private ManifestConfiguration manifest;
48  
49      private Map<String, String> manifestEntries = new LinkedHashMap<>();
50  
51      private List<ManifestSection> manifestSections = new LinkedList<>();
52  
53      /**
54       * @since 2.2
55       */
56      private boolean forced = true;
57  
58      /**
59       * @since 2.3
60       */
61      private File pomPropertiesFile;
62  
63      /**
64       * <p>isCompress.</p>
65       *
66       * @return {@link #compress}
67       */
68      public boolean isCompress()
69      {
70          return compress;
71      }
72  
73      /**
74       * <p>isRecompressAddedZips.</p>
75       *
76       * @return {@link #recompressAddedZips}
77       */
78      public boolean isRecompressAddedZips()
79      {
80          return recompressAddedZips;
81      }
82  
83      /**
84       * <p>Setter for the field <code>recompressAddedZips</code>.</p>
85       *
86       * @param recompressAddedZips {@link #recompressAddedZips}
87       */
88      public void setRecompressAddedZips( boolean recompressAddedZips )
89      {
90          this.recompressAddedZips = recompressAddedZips;
91      }
92  
93      /**
94       * <p>isIndex.</p>
95       *
96       * @return {@link #index}
97       */
98      public boolean isIndex()
99      {
100         return index;
101     }
102 
103     /**
104      * <p>isAddMavenDescriptor.</p>
105      *
106      * @return {@link #addMavenDescriptor}
107      */
108     public boolean isAddMavenDescriptor()
109     {
110         return addMavenDescriptor;
111     }
112 
113     /**
114      * <p>Getter for the field <code>manifestFile</code>.</p>
115      *
116      * @return {@link #manifestFile}
117      */
118     public File getManifestFile()
119     {
120         return manifestFile;
121     }
122 
123     /**
124      * <p>Getter for the field <code>manifest</code>.</p>
125      *
126      * @return {@link #manifest}
127      */
128     //TODO: Change the name of this method into getManifestConfiguration()
129     public ManifestConfiguration getManifest()
130     {
131         if ( manifest == null )
132         {
133             manifest = new ManifestConfiguration();
134         }
135         return manifest;
136     }
137 
138     /**
139      * <p>Setter for the field <code>compress</code>.</p>
140      *
141      * @param compress set compress to true/false.
142      */
143     public void setCompress( boolean compress )
144     {
145         this.compress = compress;
146     }
147 
148     /**
149      * <p>Setter for the field <code>index</code>.</p>
150      *
151      * @param index set index to true/false.
152      */
153     public void setIndex( boolean index )
154     {
155         this.index = index;
156     }
157 
158     /**
159      * <p>Setter for the field <code>addMavenDescriptor</code>.</p>
160      *
161      * @param addMavenDescriptor activate to add maven descriptor or not.
162      */
163     public void setAddMavenDescriptor( boolean addMavenDescriptor )
164     {
165         this.addMavenDescriptor = addMavenDescriptor;
166     }
167 
168     /**
169      * <p>Setter for the field <code>manifestFile</code>.</p>
170      *
171      * @param manifestFile The manifest file.
172      */
173     public void setManifestFile( File manifestFile )
174     {
175         this.manifestFile = manifestFile;
176     }
177 
178     /**
179      * <p>Setter for the field <code>manifest</code>.</p>
180      *
181      * @param manifest {@link org.apache.maven.archiver.ManifestConfiguration}
182      */
183     public void setManifest( ManifestConfiguration manifest )
184     {
185         this.manifest = manifest;
186     }
187 
188     /**
189      * <p>addManifestEntry.</p>
190      *
191      * @param key The key of the entry.
192      * @param value The value of the entry.
193      */
194     public void addManifestEntry( String key, String value )
195     {
196         manifestEntries.put( key, value );
197     }
198 
199     /**
200      * <p>addManifestEntries.</p>
201      *
202      * @param map The whole map which should be added.
203      */
204     public void addManifestEntries( Map<String, String> map )
205     {
206         manifestEntries.putAll( map );
207     }
208 
209     /**
210      * <p>isManifestEntriesEmpty.</p>
211      *
212      * @return are there entries true yes false otherwise.
213      */
214     public boolean isManifestEntriesEmpty()
215     {
216         return manifestEntries.isEmpty();
217     }
218 
219     /**
220      * <p>Getter for the field <code>manifestEntries</code>.</p>
221      *
222      * @return {@link #manifestEntries}
223      */
224     public Map<String, String> getManifestEntries()
225     {
226         return manifestEntries;
227     }
228 
229     /**
230      * <p>Setter for the field <code>manifestEntries</code>.</p>
231      *
232      * @param manifestEntries {@link #manifestEntries}
233      */
234     public void setManifestEntries( Map<String, String> manifestEntries )
235     {
236         this.manifestEntries = manifestEntries;
237     }
238 
239     /**
240      * <p>addManifestSection.</p>
241      *
242      * @param section {@link org.apache.maven.archiver.ManifestSection}
243      */
244     public void addManifestSection( ManifestSection section )
245     {
246         manifestSections.add( section );
247     }
248 
249     /**
250      * <p>addManifestSections.</p>
251      *
252      * @param list Added list of {@link org.apache.maven.archiver.ManifestSection}.
253      */
254     public void addManifestSections( List<ManifestSection> list )
255     {
256         manifestSections.addAll( list );
257     }
258 
259     /**
260      * <p>isManifestSectionsEmpty.</p>
261      *
262      * @return if manifestSections is empty or not.
263      */
264     public boolean isManifestSectionsEmpty()
265     {
266         return manifestSections.isEmpty();
267     }
268 
269     /**
270      * <p>Getter for the field <code>manifestSections</code>.</p>
271      *
272      * @return {@link #manifestSections}
273      */
274     public List<ManifestSection> getManifestSections()
275     {
276         return manifestSections;
277     }
278 
279     /**
280      * <p>Setter for the field <code>manifestSections</code>.</p>
281      *
282      * @param manifestSections set The list of {@link org.apache.maven.archiver.ManifestSection}.
283      */
284     public void setManifestSections( List<ManifestSection> manifestSections )
285     {
286         this.manifestSections = manifestSections;
287     }
288 
289     /**
290      * <p>
291      * Returns, whether recreating the archive is forced (default). Setting this option to false means, that the
292      * archiver should compare the timestamps of included files with the timestamp of the target archive and rebuild the
293      * archive only, if the latter timestamp precedes the former timestamps. Checking for timestamps will typically
294      * offer a performance gain (in particular, if the following steps in a build can be suppressed, if an archive isn't
295      * recrated) on the cost that you get inaccurate results from time to time. In particular, removal of source files
296      * won't be detected.
297      * </p>
298      * <p>
299      * An archiver doesn't necessarily support checks for uptodate. If so, setting this option to true will simply be
300      * ignored.
301      * </p>
302      *
303      * @return True, if the target archive should always be created; false otherwise
304      * @see #setForced(boolean)
305      */
306     public boolean isForced()
307     {
308         return forced;
309     }
310 
311     /**
312      * <p>
313      * Sets, whether recreating the archive is forced (default). Setting this option to false means, that the archiver
314      * should compare the timestamps of included files with the timestamp of the target archive and rebuild the archive
315      * only, if the latter timestamp precedes the former timestamps. Checking for timestamps will typically offer a
316      * performance gain (in particular, if the following steps in a build can be suppressed, if an archive isn't
317      * recrated) on the cost that you get inaccurate results from time to time. In particular, removal of source files
318      * won't be detected.
319      * </p>
320      * <p>
321      * An archiver doesn't necessarily support checks for uptodate. If so, setting this option to true will simply be
322      * ignored.
323      * </p>
324      *
325      * @param forced True, if the target archive should always be created; false otherwise
326      * @see #isForced()
327      */
328     public void setForced( boolean forced )
329     {
330         this.forced = forced;
331     }
332 
333     /**
334      * Returns the location of the "pom.properties" file. May be null, in which case a default value is choosen.
335      *
336      * @return "pom.properties" location or null.
337      */
338     public File getPomPropertiesFile()
339     {
340         return pomPropertiesFile;
341     }
342 
343     /**
344      * Sets the location of the "pom.properties" file. May be null, in which case a default value is choosen.
345      *
346      * @param pomPropertiesFile "pom.properties" location or null.
347      */
348     public void setPomPropertiesFile( File pomPropertiesFile )
349     {
350         this.pomPropertiesFile = pomPropertiesFile;
351     }
352 }