34
34
import java .util .NoSuchElementException ;
35
35
import java .util .Set ;
36
36
import javax .annotation .Nonnull ;
37
- import org .codehaus .plexus .PlexusConstants ;
38
- import org .codehaus .plexus .PlexusContainer ;
37
+ import javax .inject .Inject ;
38
+ import javax .inject .Provider ;
39
+
39
40
import org .codehaus .plexus .archiver .manager .ArchiverManager ;
40
41
import org .codehaus .plexus .archiver .manager .NoSuchArchiverException ;
41
- import org .codehaus .plexus .component .repository .exception .ComponentLookupException ;
42
42
import org .codehaus .plexus .components .io .attributes .PlexusIoResourceAttributes ;
43
43
import org .codehaus .plexus .components .io .attributes .SimpleResourceAttributes ;
44
44
import org .codehaus .plexus .components .io .functions .ResourceAttributeSupplier ;
49
49
import org .codehaus .plexus .components .io .resources .PlexusIoResource ;
50
50
import org .codehaus .plexus .components .io .resources .PlexusIoResourceCollection ;
51
51
import org .codehaus .plexus .components .io .resources .proxy .PlexusIoProxyResourceCollection ;
52
- import org .codehaus .plexus .context .Context ;
53
- import org .codehaus .plexus .context .ContextException ;
54
- import org .codehaus .plexus .logging .AbstractLogEnabled ;
55
- import org .codehaus .plexus .logging .Logger ;
56
- import org .codehaus .plexus .logging .console .ConsoleLogger ;
57
- import org .codehaus .plexus .personality .plexus .lifecycle .phase .Contextualizable ;
52
+ import org .slf4j .Logger ;
53
+ import org .slf4j .LoggerFactory ;
54
+
58
55
import static org .codehaus .plexus .archiver .util .DefaultArchivedFileSet .archivedFileSet ;
59
56
import static org .codehaus .plexus .archiver .util .DefaultFileSet .fileSet ;
60
57
61
58
public abstract class AbstractArchiver
62
- extends AbstractLogEnabled
63
- implements Archiver , Contextualizable , FinalizerEnabled
59
+ implements Archiver , FinalizerEnabled
64
60
{
65
61
66
- private Logger logger ;
62
+ private final Logger logger = LoggerFactory .getLogger ( getClass () );
63
+
64
+ protected Logger getLogger ()
65
+ {
66
+ return logger ;
67
+ }
67
68
68
69
private File destFile ;
69
70
@@ -135,8 +136,12 @@ public abstract class AbstractArchiver
135
136
*/
136
137
private String overrideGroupName ;
137
138
138
- // contextualized.
139
- private ArchiverManager archiverManager ;
139
+ /**
140
+ * Injected: Allows us to pull the ArchiverManager instance out of the container without causing a chicken-and-egg
141
+ * instantiation/composition problem.
142
+ */
143
+ @ Inject
144
+ private Provider <ArchiverManager > archiverManagerProvider ;
140
145
141
146
private static class AddedResourceCollection
142
147
{
@@ -186,7 +191,7 @@ public void setDuplicateBehavior( final String duplicate )
186
191
if ( !Archiver .DUPLICATES_VALID_BEHAVIORS .contains ( duplicate ) )
187
192
{
188
193
throw new IllegalArgumentException (
189
- "Invalid duplicate-file behavior: \ ' " + duplicate + "\ ' . Please specify one of: "
194
+ "Invalid duplicate-file behavior: '" + duplicate + "'. Please specify one of: "
190
195
+ Archiver .DUPLICATES_VALID_BEHAVIORS );
191
196
}
192
197
@@ -524,15 +529,15 @@ public ResourceIterator getResources()
524
529
return new ResourceIterator ()
525
530
{
526
531
527
- private final Iterator addedResourceIter = resources .iterator ();
532
+ private final Iterator < Object > addedResourceIter = resources .iterator ();
528
533
529
534
private AddedResourceCollection currentResourceCollection ;
530
535
531
536
private Iterator ioResourceIter ;
532
537
533
538
private ArchiveEntry nextEntry ;
534
539
535
- private final Set <String > seenEntries = new HashSet <String >();
540
+ private final Set <String > seenEntries = new HashSet <>();
536
541
537
542
@ Override
538
543
public boolean hasNext ()
@@ -727,24 +732,6 @@ public void setDestFile( final File destFile )
727
732
}
728
733
}
729
734
730
- @ Override
731
- protected Logger getLogger ()
732
- {
733
- if ( logger == null )
734
- {
735
- if ( super .getLogger () != null )
736
- {
737
- logger = super .getLogger ();
738
- }
739
- else
740
- {
741
- logger = new ConsoleLogger ( Logger .LEVEL_INFO , "console" );
742
- }
743
- }
744
-
745
- return logger ;
746
- }
747
-
748
735
protected PlexusIoResourceCollection asResourceCollection ( final ArchivedFileSet fileSet , Charset charset )
749
736
throws ArchiverException
750
737
{
@@ -753,7 +740,7 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
753
740
final PlexusIoResourceCollection resources ;
754
741
try
755
742
{
756
- resources = archiverManager .getResourceCollection ( archiveFile );
743
+ resources = archiverManagerProvider . get () .getResourceCollection ( archiveFile );
757
744
}
758
745
catch ( final NoSuchArchiverException e )
759
746
{
@@ -880,26 +867,6 @@ public void addArchivedFileSet( @Nonnull final File archiveFile )
880
867
addArchivedFileSet ( archivedFileSet ( archiveFile ).includeEmptyDirs ( includeEmptyDirs ) );
881
868
}
882
869
883
- /**
884
- * Allows us to pull the ArchiverManager instance out of the container without causing a chicken-and-egg
885
- * instantiation/composition problem.
886
- */
887
- @ Override
888
- public void contextualize ( final Context context )
889
- throws ContextException
890
- {
891
- final PlexusContainer container = (PlexusContainer ) context .get ( PlexusConstants .PLEXUS_KEY );
892
-
893
- try
894
- {
895
- archiverManager = (ArchiverManager ) container .lookup ( ArchiverManager .ROLE );
896
- }
897
- catch ( final ComponentLookupException e )
898
- {
899
- throw new ContextException ( "Error retrieving ArchiverManager instance: " + e .getMessage (), e );
900
- }
901
- }
902
-
903
870
@ Override
904
871
public boolean isForced ()
905
872
{
@@ -917,7 +884,7 @@ public void addArchiveFinalizer( final ArchiveFinalizer finalizer )
917
884
{
918
885
if ( finalizers == null )
919
886
{
920
- finalizers = new ArrayList <ArchiveFinalizer >();
887
+ finalizers = new ArrayList <>();
921
888
}
922
889
923
890
finalizers .add ( finalizer );
@@ -946,7 +913,7 @@ protected boolean isUptodate()
946
913
}
947
914
final long destTimestamp = getFileLastModifiedTime (zipFile );
948
915
949
- final Iterator it = resources .iterator ();
916
+ final Iterator < Object > it = resources .iterator ();
950
917
if ( !it .hasNext () )
951
918
{
952
919
getLogger ().debug ( "isUp2date: false (No input files.)" );
@@ -1314,14 +1281,7 @@ public void configureReproducibleBuild( FileTime lastModifiedTime )
1314
1281
setLastModifiedTime ( normalizeLastModifiedTime ( lastModifiedTime ) );
1315
1282
1316
1283
// 2. sort filenames in each directory when scanning filesystem
1317
- setFilenameComparator ( new Comparator <String >()
1318
- {
1319
- @ Override
1320
- public int compare ( String s1 , String s2 )
1321
- {
1322
- return s1 .compareTo ( s2 );
1323
- }
1324
- } );
1284
+ setFilenameComparator ( String ::compareTo );
1325
1285
1326
1286
// 3. ignore file/directory mode from filesystem, since they may vary based on local user umask
1327
1287
// notice: this overrides execute bit on Unix (that is already ignored on Windows)
0 commit comments