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