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