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