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