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