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 1634380 2014-10-26 19:01:23Z michaelo $
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      public boolean isCompress()
64      {
65          return compress;
66      }
67  
68      public boolean isRecompressAddedZips()
69      {
70          return recompressAddedZips;
71      }
72  
73      public void setRecompressAddedZips( boolean recompressAddedZips )
74      {
75          this.recompressAddedZips = recompressAddedZips;
76      }
77  
78      public boolean isIndex()
79      {
80          return index;
81      }
82  
83      public boolean isAddMavenDescriptor()
84      {
85          return addMavenDescriptor;
86      }
87  
88      public File getManifestFile()
89      {
90          return manifestFile;
91      }
92  
93      public ManifestConfiguration getManifest()
94      {
95          if ( manifest == null )
96          {
97              manifest = new ManifestConfiguration();
98          }
99          return manifest;
100     }
101 
102     public void setCompress( boolean compress )
103     {
104         this.compress = compress;
105     }
106 
107     public void setIndex( boolean index )
108     {
109         this.index = index;
110     }
111 
112     public void setAddMavenDescriptor( boolean addMavenDescriptor )
113     {
114         this.addMavenDescriptor = addMavenDescriptor;
115     }
116 
117     public void setManifestFile( File manifestFile )
118     {
119         this.manifestFile = manifestFile;
120     }
121 
122     public void setManifest( ManifestConfiguration manifest )
123     {
124         this.manifest = manifest;
125     }
126 
127     public void addManifestEntry( String key, String value )
128     {
129         manifestEntries.put( key, value );
130     }
131 
132     public void addManifestEntries( Map<String,String> map )
133     {
134         manifestEntries.putAll( map );
135     }
136 
137     public boolean isManifestEntriesEmpty()
138     {
139         return manifestEntries.isEmpty();
140     }
141 
142     public Map<String, String> getManifestEntries()
143     {
144         return manifestEntries;
145     }
146 
147     public void setManifestEntries( Map<String, String> manifestEntries )
148     {
149         this.manifestEntries = manifestEntries;
150     }
151 
152     public void addManifestSection( ManifestSection section )
153     {
154         manifestSections.add( section );
155     }
156 
157     public void addManifestSections( List<ManifestSection> list )
158     {
159         manifestSections.addAll( list );
160     }
161 
162     public boolean isManifestSectionsEmpty()
163     {
164         return manifestSections.isEmpty();
165     }
166 
167     public List<ManifestSection> getManifestSections()
168     {
169         return manifestSections;
170     }
171 
172     public void setManifestSections( List<ManifestSection> manifestSections )
173     {
174         this.manifestSections = manifestSections;
175     }
176 
177     /**
178      * <p>Returns, whether recreating the archive is forced (default). Setting
179      * this option to false means, that the archiver should compare the
180      * timestamps of included files with the timestamp of the target archive
181      * and rebuild the archive only, if the latter timestamp precedes the
182      * former timestamps. Checking for timestamps will typically offer a
183      * performance gain (in particular, if the following steps in a build
184      * can be suppressed, if an archive isn't recrated) on the cost that
185      * you get inaccurate results from time to time. In particular, removal
186      * of source files won't be detected.</p>
187      * <p>An archiver doesn't necessarily support checks for uptodate. If
188      * so, setting this option to true will simply be ignored.</p>
189      *
190      * @return True, if the target archive should always be created; false
191      *         otherwise
192      * @see #setForced(boolean)
193      */
194     public boolean isForced()
195     {
196         return forced;
197     }
198 
199     /**
200      * <p>Sets, whether recreating the archive is forced (default). Setting
201      * this option to false means, that the archiver should compare the
202      * timestamps of included files with the timestamp of the target archive
203      * and rebuild the archive only, if the latter timestamp precedes the
204      * former timestamps. Checking for timestamps will typically offer a
205      * performance gain (in particular, if the following steps in a build
206      * can be suppressed, if an archive isn't recrated) on the cost that
207      * you get inaccurate results from time to time. In particular, removal
208      * of source files won't be detected.</p>
209      * <p>An archiver doesn't necessarily support checks for uptodate. If
210      * so, setting this option to true will simply be ignored.</p>
211      *
212      * @param forced True, if the target archive should always be created; false
213      *               otherwise
214      * @see #isForced()
215      */
216     public void setForced( boolean forced )
217     {
218         this.forced = forced;
219     }
220 
221     /**
222      * Returns the location of the "pom.properties" file.
223      * May be null, in which case a default value is choosen.
224      *
225      * @return "pom.properties" location or null.
226      */
227     public File getPomPropertiesFile()
228     {
229         return pomPropertiesFile;
230     }
231 
232     /**
233      * Sets the location of the "pom.properties" file.
234      * May be null, in which case a default value is choosen.
235      *
236      * @param pomPropertiesFile "pom.properties" location or null.
237      */
238     public void setPomPropertiesFile( File pomPropertiesFile )
239     {
240         this.pomPropertiesFile = pomPropertiesFile;
241     }
242 }