Skip to content

Commit a4a6b07

Browse files
jorsolhboutemy
authored andcommitted
Refactor to use FileTime API
Signed-off-by: Jorge Solórzano <[email protected]>
1 parent 58e9ae4 commit a4a6b07

13 files changed

+311
-50
lines changed

src/main/java/org/codehaus/plexus/archiver/AbstractArchiver.java

+45-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.reflect.UndeclaredThrowableException;
2323
import java.nio.charset.Charset;
2424
import java.nio.file.Files;
25+
import java.nio.file.attribute.FileTime;
2526
import java.util.ArrayList;
2627
import java.util.Comparator;
2728
import java.util.Date;
@@ -107,10 +108,7 @@ public abstract class AbstractArchiver
107108
*/
108109
private boolean useJvmChmod = true;
109110

110-
/**
111-
* @since 4.2.0
112-
*/
113-
private Date lastModifiedDate;
111+
private FileTime lastModifiedTime;
114112

115113
/**
116114
* @since 4.2.0
@@ -1208,16 +1206,36 @@ public void setIgnorePermissions( final boolean ignorePermissions )
12081206
this.ignorePermissions = ignorePermissions;
12091207
}
12101208

1209+
/**
1210+
* @deprecated Use {@link #setLastModifiedTime(FileTime)} instead.
1211+
*/
12111212
@Override
1213+
@Deprecated
12121214
public void setLastModifiedDate( Date lastModifiedDate )
12131215
{
1214-
this.lastModifiedDate = lastModifiedDate;
1216+
this.lastModifiedTime = lastModifiedDate != null ? FileTime.fromMillis( lastModifiedDate.getTime() ) : null;
12151217
}
12161218

1219+
/**
1220+
* @deprecated Use {@link #getLastModifiedTime()} instead.
1221+
*/
12171222
@Override
1223+
@Deprecated
12181224
public Date getLastModifiedDate()
12191225
{
1220-
return lastModifiedDate;
1226+
return lastModifiedTime != null ? new Date( lastModifiedTime.toMillis() ) : null;
1227+
}
1228+
1229+
@Override
1230+
public void setLastModifiedTime( FileTime lastModifiedTime )
1231+
{
1232+
this.lastModifiedTime = lastModifiedTime;
1233+
}
1234+
1235+
@Override
1236+
public FileTime getLastModifiedTime()
1237+
{
1238+
return lastModifiedTime;
12211239
}
12221240

12231241
@Override
@@ -1279,11 +1297,21 @@ public String getOverrideGroupName()
12791297
return overrideGroupName;
12801298
}
12811299

1300+
/**
1301+
* @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead.
1302+
*/
12821303
@Override
1304+
@Deprecated
12831305
public void configureReproducible( Date lastModifiedDate )
1306+
{
1307+
configureReproducibleBuild( FileTime.fromMillis( lastModifiedDate.getTime() ) );
1308+
}
1309+
1310+
@Override
1311+
public void configureReproducibleBuild( FileTime lastModifiedTime )
12841312
{
12851313
// 1. force last modified date
1286-
setLastModifiedDate( normalizeLastModifiedDate( lastModifiedDate ) );
1314+
setLastModifiedTime( normalizeLastModifiedTime ( lastModifiedTime ) );
12871315

12881316
// 2. sort filenames in each directory when scanning filesystem
12891317
setFilenameComparator( new Comparator<String>()
@@ -1309,14 +1337,18 @@ public int compare( String s1, String s2 )
13091337

13101338
/**
13111339
* Normalize last modified time value to get reproducible archive entries, based on
1312-
* archive binary format (tar uses UTC timestamp but zip uses local time then requires
1313-
* tweaks to make the value reproducible whatever the current timezone is).
1340+
* archive binary format.
1341+
*
1342+
* <p>tar uses UTC timestamp, but zip uses local time then requires
1343+
* tweaks to make the value reproducible whatever the current timezone is.
1344+
*
1345+
* @param lastModifiedTime The last modification time
1346+
* @return The normalized last modification time
13141347
*
1315-
* @param lastModifiedDate
1316-
* @return
1348+
* @see #configureReproducibleBuild(FileTime)
13171349
*/
1318-
protected Date normalizeLastModifiedDate( Date lastModifiedDate )
1350+
protected FileTime normalizeLastModifiedTime( FileTime lastModifiedTime )
13191351
{
1320-
return lastModifiedDate;
1352+
return lastModifiedTime;
13211353
}
13221354
}

src/main/java/org/codehaus/plexus/archiver/Archiver.java

+43-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.nio.charset.Charset;
22+
import java.nio.file.attribute.FileTime;
2223
import java.util.Comparator;
2324
import java.util.Date;
2425
import java.util.HashSet;
2526
import java.util.Map;
2627
import java.util.Set;
28+
2729
import javax.annotation.Nonnull;
2830
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
2931
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
@@ -390,14 +392,38 @@ ResourceIterator getResources()
390392
*
391393
* @param lastModifiedDate
392394
* @since 4.2.0
395+
* @deprecated Use {@link #setLastModifiedTime(FileTime)} instead
393396
*/
397+
@Deprecated
394398
void setLastModifiedDate( final Date lastModifiedDate );
395399

396400
/**
397401
* @since 4.2.0
402+
* @deprecated Use {@link #getLastModifiedTime()} instead
398403
*/
404+
@Deprecated
399405
Date getLastModifiedDate();
400406

407+
/**
408+
* Sets the last modification time of the entries (if non null).
409+
*
410+
* @param lastModifiedTime to set in the archive entries
411+
*
412+
* @see #getLastModifiedTime()
413+
* @since 4.3.0
414+
*/
415+
void setLastModifiedTime( final FileTime lastModifiedTime );
416+
417+
/**
418+
* Returns the last modification time of the archiver.
419+
*
420+
* @return The last modification time of the archiver, null if not specified
421+
*
422+
* @see #setLastModifiedTime(FileTime)
423+
* @since 4.3.0
424+
*/
425+
FileTime getLastModifiedTime();
426+
401427
/**
402428
* Set filename comparator, used to sort file entries when scanning directories since File.list() does not
403429
* guarantee any order.
@@ -446,6 +472,17 @@ ResourceIterator getResources()
446472
*/
447473
String getOverrideGroupName();
448474

475+
/**
476+
* This method is obsolete and will just call {@link #configureReproducibleBuild(FileTime)}
477+
* with the Date transformed into FileTime.
478+
*
479+
* @param lastModifiedDate the date to use for archive entries last modified time
480+
* @since 4.2.0
481+
* @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead.
482+
*/
483+
@Deprecated
484+
void configureReproducible( Date lastModifiedDate );
485+
449486
/**
450487
* Configure the archiver to create archives in a reproducible way (see
451488
* <a href="https://reproducible-builds.org/">Reproducible Builds</a>).
@@ -455,9 +492,11 @@ ResourceIterator getResources()
455492
* <li>defined entries timestamp</li>
456493
* <li>and reproducible entries Unix mode.</li>
457494
* </ul>
458-
*
459-
* @param lastModifiedDate the date to use for archive entries last modified time
460-
* @since 4.2.0
495+
*
496+
* @param lastModifiedTime The last modification time of the entries
497+
*
498+
* @see <a href="https://reproducible-builds.org/">Reproducible Builds</a>
499+
* @since 4.3.0
461500
*/
462-
void configureReproducible( Date lastModifiedDate );
501+
void configureReproducibleBuild( FileTime lastModifiedTime );
463502
}

src/main/java/org/codehaus/plexus/archiver/diags/DelgatingArchiver.java

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.IOException;
2020
import java.nio.charset.Charset;
21+
import java.nio.file.attribute.FileTime;
2122
import java.util.Comparator;
2223
import java.util.Date;
2324
import java.util.Map;
@@ -333,18 +334,38 @@ public void setIgnorePermissions( boolean ignorePermissions )
333334
target.setIgnorePermissions( ignorePermissions );
334335
}
335336

337+
/**
338+
* @deprecated Use {@link #setLastModifiedTime(FileTime)} instead.
339+
*/
336340
@Override
341+
@Deprecated
337342
public void setLastModifiedDate( final Date lastModifiedDate )
338343
{
339344
target.setLastModifiedDate( lastModifiedDate );
340345
}
341346

347+
/**
348+
* @deprecated Use {@link #getLastModifiedTime()} instead.
349+
*/
342350
@Override
351+
@Deprecated
343352
public Date getLastModifiedDate()
344353
{
345354
return target.getLastModifiedDate();
346355
}
347356

357+
@Override
358+
public void setLastModifiedTime( final FileTime lastModifiedTime )
359+
{
360+
target.setLastModifiedTime( lastModifiedTime );
361+
}
362+
363+
@Override
364+
public FileTime getLastModifiedTime()
365+
{
366+
return target.getLastModifiedTime();
367+
}
368+
348369
@Override
349370
public void setFilenameComparator( final Comparator<String> filenameComparator )
350371
{
@@ -399,10 +420,20 @@ public String getOverrideGroupName()
399420
return target.getOverrideGroupName();
400421
}
401422

423+
/**
424+
* @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead.
425+
*/
402426
@Override
427+
@Deprecated
403428
public void configureReproducible( Date lastModifiedDate )
404429
{
405430
target.configureReproducible( lastModifiedDate );
406431
}
407432

433+
@Override
434+
public void configureReproducibleBuild( FileTime lastModifiedTime )
435+
{
436+
target.configureReproducibleBuild( lastModifiedTime );
437+
}
438+
408439
}

src/main/java/org/codehaus/plexus/archiver/diags/NoOpArchiver.java

+31
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.File;
1919
import java.io.IOException;
2020
import java.nio.charset.Charset;
21+
import java.nio.file.attribute.FileTime;
2122
import java.util.Collections;
2223
import java.util.Comparator;
2324
import java.util.Date;
@@ -348,18 +349,38 @@ public void setIgnorePermissions( boolean ignorePermissions )
348349
this.ignorePermissions = ignorePermissions;
349350
}
350351

352+
/**
353+
* @deprecated Use {@link #setLastModifiedTime(FileTime)} instead.
354+
*/
351355
@Override
356+
@Deprecated
352357
public void setLastModifiedDate( final Date lastModifiedDate )
353358
{
354359

355360
}
356361

362+
/**
363+
* @deprecated Use {@link #getLastModifiedTime()} instead.
364+
*/
357365
@Override
366+
@Deprecated
358367
public Date getLastModifiedDate()
359368
{
360369
return null;
361370
}
362371

372+
@Override
373+
public void setLastModifiedTime( final FileTime lastModifiedTime )
374+
{
375+
376+
}
377+
378+
@Override
379+
public FileTime getLastModifiedTime()
380+
{
381+
return null;
382+
}
383+
363384
@Override
364385
public void setFilenameComparator( final Comparator<String> filenameComparator )
365386
{
@@ -414,10 +435,20 @@ public String getOverrideGroupName()
414435
return null;
415436
}
416437

438+
/**
439+
* @deprecated Use {@link #configureReproducibleBuild(FileTime)} instead.
440+
*/
417441
@Override
442+
@Deprecated
418443
public void configureReproducible( Date lastModifiedDate )
419444
{
420445

421446
}
422447

448+
@Override
449+
public void configureReproducibleBuild( FileTime lastModifiedTime )
450+
{
451+
452+
}
453+
423454
}

0 commit comments

Comments
 (0)