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.ArrayList;
24  import java.util.HashMap;
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   * @version $Id: MavenArchiveConfiguration.java 1634984 2014-10-28 21:01:38Z khmarbaise $
33   * @todo is this general enough to be in Plexus Archiver?
34   */
35  public class MavenArchiveConfiguration
36  {
37      private boolean compress = true;
38  
39      private boolean recompressAddedZips = true;
40  
41      private boolean index;
42  
43      private boolean addMavenDescriptor = true;
44  
45      private File manifestFile;
46  
47      private ManifestConfiguration manifest;
48  
49      private Map<String, String> manifestEntries = new HashMap<String, String>();
50  
51      private List<ManifestSection> manifestSections = new ArrayList<ManifestSection>();
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       * @return {@link #compress}
65       */
66      public boolean isCompress()
67      {
68          return compress;
69      }
70  
71      /**
72       * @return {@link #recompressAddedZips}
73       */
74      public boolean isRecompressAddedZips()
75      {
76          return recompressAddedZips;
77      }
78  
79      /**
80       * @param recompressAddedZips {@link #recompressAddedZips}
81       */
82      public void setRecompressAddedZips( boolean recompressAddedZips )
83      {
84          this.recompressAddedZips = recompressAddedZips;
85      }
86  
87      /**
88       * @return {@link #index}
89       */
90      public boolean isIndex()
91      {
92          return index;
93      }
94  
95      /**
96       * @return {@link #addMavenDescriptor}
97       */
98      public boolean isAddMavenDescriptor()
99      {
100         return addMavenDescriptor;
101     }
102 
103     /**
104      * @return {@link #manifestFile}
105      */
106     public File getManifestFile()
107     {
108         return manifestFile;
109     }
110 
111     /**
112      * @return {@link #manifest}
113      */
114     public ManifestConfiguration getManifest()
115     {
116         if ( manifest == null )
117         {
118             manifest = new ManifestConfiguration();
119         }
120         return manifest;
121     }
122 
123     /**
124      * @param compress set compress to true/false.
125      */
126     public void setCompress( boolean compress )
127     {
128         this.compress = compress;
129     }
130 
131     /**
132      * @param index set index to true/false.
133      */
134     public void setIndex( boolean index )
135     {
136         this.index = index;
137     }
138 
139     /**
140      * @param addMavenDescriptor activate to add maven descriptor or not.
141      */
142     public void setAddMavenDescriptor( boolean addMavenDescriptor )
143     {
144         this.addMavenDescriptor = addMavenDescriptor;
145     }
146 
147     /**
148      * @param manifestFile The manifest file.
149      */
150     public void setManifestFile( File manifestFile )
151     {
152         this.manifestFile = manifestFile;
153     }
154 
155     /**
156      * @param manifest {@link ManifestConfiguration}
157      */
158     public void setManifest( ManifestConfiguration manifest )
159     {
160         this.manifest = manifest;
161     }
162 
163     /**
164      * @param key The key of the entry.
165      * @param value The value of the entry.
166      */
167     public void addManifestEntry( String key, String value )
168     {
169         manifestEntries.put( key, value );
170     }
171 
172     /**
173      * @param map The whole map which should be added.
174      */
175     public void addManifestEntries( Map<String, String> map )
176     {
177         manifestEntries.putAll( map );
178     }
179 
180     /**
181      * @return are there entries true yes false otherwise.
182      */
183     public boolean isManifestEntriesEmpty()
184     {
185         return manifestEntries.isEmpty();
186     }
187 
188     /**
189      * @return {@link #manifestEntries}
190      */
191     public Map<String, String> getManifestEntries()
192     {
193         return manifestEntries;
194     }
195 
196     /**
197      * @param manifestEntries {@link #manifestEntries}
198      */
199     public void setManifestEntries( Map<String, String> manifestEntries )
200     {
201         this.manifestEntries = manifestEntries;
202     }
203 
204     /**
205      * @param section {@link ManifestSection}
206      */
207     public void addManifestSection( ManifestSection section )
208     {
209         manifestSections.add( section );
210     }
211 
212     /**
213      * @param list Added list of {@link ManifestSection}.
214      */
215     public void addManifestSections( List<ManifestSection> list )
216     {
217         manifestSections.addAll( list );
218     }
219 
220     /**
221      * @return if manifestSections is empty or not.
222      */
223     public boolean isManifestSectionsEmpty()
224     {
225         return manifestSections.isEmpty();
226     }
227 
228     /**
229      * @return {@link #manifestSections}
230      */
231     public List<ManifestSection> getManifestSections()
232     {
233         return manifestSections;
234     }
235 
236     /**
237      * @param manifestSections set The list of {@link ManifestSection}.
238      */
239     public void setManifestSections( List<ManifestSection> manifestSections )
240     {
241         this.manifestSections = manifestSections;
242     }
243 
244     /**
245      * <p>
246      * Returns, whether recreating the archive is forced (default). Setting this option to false means, that the
247      * archiver should compare the timestamps of included files with the timestamp of the target archive and rebuild the
248      * archive only, if the latter timestamp precedes the former timestamps. Checking for timestamps will typically
249      * offer a performance gain (in particular, if the following steps in a build can be suppressed, if an archive isn't
250      * recrated) on the cost that you get inaccurate results from time to time. In particular, removal of source files
251      * won't be detected.
252      * </p>
253      * <p>
254      * An archiver doesn't necessarily support checks for uptodate. If so, setting this option to true will simply be
255      * ignored.
256      * </p>
257      *
258      * @return True, if the target archive should always be created; false otherwise
259      * @see #setForced(boolean)
260      */
261     public boolean isForced()
262     {
263         return forced;
264     }
265 
266     /**
267      * <p>
268      * Sets, whether recreating the archive is forced (default). Setting this option to false means, that the archiver
269      * should compare the timestamps of included files with the timestamp of the target archive and rebuild the archive
270      * only, if the latter timestamp precedes the former timestamps. Checking for timestamps will typically offer a
271      * performance gain (in particular, if the following steps in a build can be suppressed, if an archive isn't
272      * recrated) on the cost that you get inaccurate results from time to time. In particular, removal of source files
273      * won't be detected.
274      * </p>
275      * <p>
276      * An archiver doesn't necessarily support checks for uptodate. If so, setting this option to true will simply be
277      * ignored.
278      * </p>
279      *
280      * @param forced True, if the target archive should always be created; false otherwise
281      * @see #isForced()
282      */
283     public void setForced( boolean forced )
284     {
285         this.forced = forced;
286     }
287 
288     /**
289      * Returns the location of the "pom.properties" file. May be null, in which case a default value is choosen.
290      *
291      * @return "pom.properties" location or null.
292      */
293     public File getPomPropertiesFile()
294     {
295         return pomPropertiesFile;
296     }
297 
298     /**
299      * Sets the location of the "pom.properties" file. May be null, in which case a default value is choosen.
300      *
301      * @param pomPropertiesFile "pom.properties" location or null.
302      */
303     public void setPomPropertiesFile( File pomPropertiesFile )
304     {
305         this.pomPropertiesFile = pomPropertiesFile;
306     }
307 }