/
Archiver.java
479 lines (408 loc) · 14.9 KB
/
Archiver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
/**
*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.codehaus.plexus.archiver;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
public interface Archiver
{
/**
* Default value for the dirmode attribute.
*/
int DEFAULT_DIR_MODE = UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM;
/**
* Default value for the filemode attribute.
*/
int DEFAULT_FILE_MODE = UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
/**
* Default value for the symlinkmode attribute.
*/
int DEFAULT_SYMLILNK_MODE = UnixStat.LINK_FLAG | UnixStat.DEFAULT_LINK_PERM;
String ROLE = Archiver.class.getName();
public static final String DUPLICATES_ADD = "add";
public static final String DUPLICATES_PRESERVE = "preserve";
public static final String DUPLICATES_SKIP = "skip";
public static final String DUPLICATES_FAIL = "fail";
public static final Set<String> DUPLICATES_VALID_BEHAVIORS = new HashSet<String>()
{
private static final long serialVersionUID = 1L;
{
add( DUPLICATES_ADD );
add( DUPLICATES_PRESERVE );
add( DUPLICATES_SKIP );
add( DUPLICATES_FAIL );
}
};
void createArchive()
throws ArchiverException, IOException;
/**
* Obsolete, use {@link #addFileSet(FileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addDirectory( @Nonnull File directory )
throws ArchiverException;
/**
* Obsolete, use {@link #addFileSet(FileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addDirectory( @Nonnull File directory, String prefix )
throws ArchiverException;
/**
* Obsolete, use {@link #addFileSet(FileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addDirectory( @Nonnull File directory, String[] includes, String[] excludes )
throws ArchiverException;
/**
* Obsolete, use {@link #addFileSet(FileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addDirectory( @Nonnull File directory, String prefix, String[] includes, String[] excludes )
throws ArchiverException;
/**
* Adds the given file set to the archive. This method is basically obsoleting {@link #addDirectory(File)},
* {@link #addDirectory(File, String)}, {@link #addDirectory(File, String[], String[])}, and
* {@link #addDirectory(File, String, String[], String[])}. However, as these methods are in widespread use, they
* cannot easily be made deprecated.
*
* @throws ArchiverException
* Adding the file set failed.
* @since 1.0-alpha-9
*/
void addFileSet( @Nonnull FileSet fileSet )
throws ArchiverException;
void addSymlink( String symlinkName, String symlinkDestination )
throws ArchiverException;
void addSymlink( String symlinkName, int permissions, String symlinkDestination )
throws ArchiverException;
void addFile( @Nonnull File inputFile, @Nonnull String destFileName )
throws ArchiverException;
void addFile( @Nonnull File inputFile, @Nonnull String destFileName, int permissions )
throws ArchiverException;
/**
* Obsolete, use {@link #addArchivedFileSet(ArchivedFileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
void addArchivedFileSet( @Nonnull File archiveFile )
throws ArchiverException;
/**
* Obsolete, use {@link #addArchivedFileSet(ArchivedFileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addArchivedFileSet( @Nonnull File archiveFile, String prefix )
throws ArchiverException;
/**
* Obsolete, use {@link #addArchivedFileSet(ArchivedFileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addArchivedFileSet( File archiveFile, String[] includes, String[] excludes )
throws ArchiverException;
/**
* Obsolete, use {@link #addArchivedFileSet(ArchivedFileSet)}.
* You can use "inline" of this method in your
* IDE to get the proper implementation for this release.
*
* @deprecated Will go away in next major version
*/
@Deprecated
void addArchivedFileSet( @Nonnull File archiveFile, String prefix, String[] includes, String[] excludes )
throws ArchiverException;
/**
* Adds the given archive file set to the archive. This method is basically obsoleting
* {@link #addArchivedFileSet(File)}, {@link #addArchivedFileSet(File, String[], String[])}, and
* {@link #addArchivedFileSet(File, String, String[], String[])}. However, as these methods are in widespread use,
* they cannot easily be made deprecated.
*
* Stream transformers are supported on this method
*
* @since 1.0-alpha-9
*/
void addArchivedFileSet( ArchivedFileSet fileSet )
throws ArchiverException;
/**
* Adds the given archive file set to the archive. This method is basically obsoleting
* {@link #addArchivedFileSet(File)}, {@link #addArchivedFileSet(File, String[], String[])}, and
* {@link #addArchivedFileSet(File, String, String[], String[])}. However, as these methods are in widespread use,
* they cannot easily be made deprecated.
*
* @param charset the encoding to use, particularly useful to specific non-standard filename encodings
* for some kinds of archives (for instance zip files)
*
* Stream transformers are supported on this method
*
* @param fileSet the fileSet to add
* @param charset
*
* @since 1.0-alpha-9
*/
void addArchivedFileSet( ArchivedFileSet fileSet, Charset charset )
throws ArchiverException;
/**
* Adds the given resource collection to the archive.
*
* Stream transformers are *not* supported on this method
*
* @since 1.0-alpha-10
*/
void addResource( PlexusIoResource resource, String destFileName, int permissions )
throws ArchiverException;
/**
* Adds the given resource collection to the archive.
*
* Stream transformers are supported on this method
*
* @since 1.0-alpha-10
*/
void addResources( PlexusIoResourceCollection resources )
throws ArchiverException;
File getDestFile();
void setDestFile( File destFile );
void setFileMode( int mode );
int getFileMode();
int getOverrideFileMode();
void setDefaultFileMode( int mode );
int getDefaultFileMode();
/**
* This is the forced mode that should be used regardless if set, otherwise falls back to default.
*
* @param mode
*/
void setDirectoryMode( int mode );
/**
* Gets the forced mode for directories, falling back to default if none is forced.
*
* @return
*/
int getDirectoryMode();
int getOverrideDirectoryMode();
/**
* This is the "default" value we should use if no other value is specified
*
* @param mode
*/
void setDefaultDirectoryMode( int mode );
int getDefaultDirectoryMode();
boolean getIncludeEmptyDirs();
void setIncludeEmptyDirs( boolean includeEmptyDirs );
void setDotFileDirectory( File dotFileDirectory );
/**
* Returns an iterator over instances of {@link ArchiveEntry}, which have previously been added by calls to
* {@link #addResources(PlexusIoResourceCollection)}, {@link #addResource(PlexusIoResource, String, int)},
* {@link #addFileSet(FileSet)}, etc.
*
* @since 1.0-alpha-10
*/
@Nonnull
ResourceIterator getResources()
throws ArchiverException;
/**
* @deprecated Use {@link #getResources()}
*/
Map<String, ArchiveEntry> getFiles();
/**
* <p>
* Returns, whether recreating the archive is forced (default). Setting this option to false means, that the
* archiver should compare the timestamps of included files with the timestamp of the target archive and rebuild the
* archive only, if the latter timestamp precedes the former timestamps. Checking for timestamps will typically
* offer a performance gain (in particular, if the following steps in a build can be suppressed, if an archive isn't
* recreated) on the cost that you get inaccurate results from time to time. In particular, removal of source files
* won't be detected.
* </p>
* <p>
* An archiver doesn't necessarily support checks for uptodate. If so, setting this option to true will simply be
* ignored. The method {@link #isSupportingForced()} may be called to check whether an archiver does support
* uptodate checks.
* </p>
*
* @return True, if the target archive should always be created; false otherwise
*
* @see #setForced(boolean)
* @see #isSupportingForced()
*/
boolean isForced();
/**
* <p>
* Sets, whether recreating the archive is forced (default). Setting this option to false means, that the archiver
* should compare the timestamps of included files with the timestamp of the target archive and rebuild the archive
* only, if the latter timestamp precedes the former timestamps. Checking for timestamps will typically offer a
* performance gain (in particular, if the following steps in a build can be suppressed, if an archive isn't
* recreated) on the cost that you get inaccurate results from time to time. In particular, removal of source files
* won't be detected.
* </p>
* <p>
* An archiver doesn't necessarily support checks for uptodate. If so, setting this option to true will simply be
* ignored. The method {@link #isSupportingForced()} may be called to check whether an archiver does support
* uptodate checks.
* </p>
*
* @param forced
* True, if the target archive should always be created; false otherwise
*
* @see #isForced()
* @see #isSupportingForced()
*/
void setForced( boolean forced );
/**
* Returns, whether the archive supports uptodate checks. If so, you may set {@link #setForced(boolean)} to true.
*
* @return True, if the archiver does support uptodate checks, false otherwise
*
* @see #setForced(boolean)
* @see #isForced()
*/
boolean isSupportingForced();
/**
* Returns the behavior of this archiver when duplicate files are detected.
*/
String getDuplicateBehavior();
/**
* Set the behavior of this archiver when duplicate files are detected. One of: <br>
* <ul>
* <li>add - Add the duplicates to the archive as duplicate entries</li>
* <li>skip/preserve - Leave the first entry encountered in the archive, skip the new one</li>
* <li>fail - throw an {@link ArchiverException}</li>
* </ul>
* <br>
* See {@link Archiver#DUPLICATES_ADD}, {@link Archiver#DUPLICATES_SKIP}, {@link Archiver#DUPLICATES_PRESERVE},
* {@link Archiver#DUPLICATES_FAIL}.
*/
void setDuplicateBehavior( String duplicate );
/**
* to use or not the jvm method for file permissions: user all <b>not active for group permissions</b>
*
* @since 1.1
* @param useJvmChmod
* @deprecated this setting is now ignored. The jvm is always used.
*/
@Deprecated
void setUseJvmChmod( boolean useJvmChmod );
/**
*
* @since 1.1
* @return
* @deprecated this setting is now ignored. The jvm is always used.
*/
@Deprecated
boolean isUseJvmChmod();
/**
* @since 1.1
*/
boolean isIgnorePermissions();
/**
* @since 1.1
*/
void setIgnorePermissions( final boolean ignorePermissions );
/**
* Define forced last modification date for entries (if non null).
*
* @param lastModifiedDate
* @since 4.2.0
*/
void setLastModifiedDate( final Date lastModifiedDate );
/**
* @since 4.2.0
*/
Date getLastModifiedDate();
/**
* Set filename comparator, used to sort file entries when scanning directories since File.list() does not
* guarantee any order.
*
* @since 4.2.0
*/
void setFilenameComparator( Comparator<String> filenameComparator );
/**
* @since 4.2.0
*/
void setOverrideUid( int uid );
/**
* @since 4.2.0
*/
void setOverrideUserName( String userName );
/**
* @since 4.2.0
*/
int getOverrideUid();
/**
* @since 4.2.0
*/
String getOverrideUserName();
/**
* @since 4.2.0
*/
void setOverrideGid( int gid );
/**
* @since 4.2.0
*/
void setOverrideGroupName( String groupName );
/**
* @since 4.2.0
*/
int getOverrideGid();
/**
* @since 4.2.0
*/
String getOverrideGroupName();
/**
* Configure the archiver to create archives in a reproducible way (see
* <a href="https://reproducible-builds.org/">Reproducible Builds</a>).
* <p>This will configure:
* <ul>
* <li>reproducible archive entries order,</li>
* <li>defined entries timestamp</li>
* <li>and reproducible entries Unix mode.</li>
* </ul>
*
* @param lastModifiedDate the date to use for archive entries last modified time
* @since 4.2.0
*/
void configureReproducible( Date lastModifiedDate );
}