Skip to content

Commit 04648ea

Browse files
committed
Merge remote-tracking branch 'origin/2.x'
Conflicts: ReleaseNotes.md pom.xml
2 parents aee7634 + 29f5c77 commit 04648ea

File tree

10 files changed

+350
-142
lines changed

10 files changed

+350
-142
lines changed

ReleaseNotes.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,35 @@ Plexus Archiver and Plexus-IO combined release notes
44
Since archiver depends on a given version of IO this list is cumulative,
55
any version includes *all* changes below.
66

7+
8+
Plexus Archiver - Version 3.0.1
9+
------
10+
** Improvement
11+
12+
Switched to pure-java snappy. Fixed issue #3
13+
714
Plexus Archiver - Version 3.0
815
------
916
** Improvement
1017

1118
* [PLXCOMP-282] - Add Snappy compression support
1219

20+
Plexus Components - Version plexus-archiver-2.10.3
21+
-----
22+
23+
Issue #6 fix
24+
25+
Plexus Components - Version plexus-archiver-2.10.2
26+
-----
27+
28+
https://issues.apache.org/jira/browse/MASSEMBLY-769 fix.
29+
30+
31+
Plexus Components - Version plexus-archiver-2.10.1
32+
-----
33+
34+
https://issues.apache.org/jira/browse/MASSEMBLY-768 fix.
35+
1336
Plexus Components - Version plexus-archiver-2.10
1437
-----
1538

@@ -27,8 +50,6 @@ Plexus Components - Version plexus-io-2.5
2750
* Removed zip supporting PlexusIoZipFileResourceCollection; which now exists in plexus-archiver. (Drop in replacement,
2851
just change/add jar file).
2952

30-
>>>>>>> 2.x
31-
3253
Plexus Components - Version plexus-archiver-2.9.1
3354
-----
3455

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

Lines changed: 98 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public abstract class AbstractArchiver
7373
/**
7474
* A list of the following objects:
7575
* <ul>
76-
* <li>Instances of {@link ArchiveEntry}, which are passed back by {@link #getResources()} without modifications.</li>
76+
* <li>Instances of {@link ArchiveEntry}, which are passed back by {@link #getResources()} without modifications
77+
* .</li>
7778
* <li>Instances of {@link PlexusIoResourceCollection}, which are converted into an {@link Iterator} over instances
7879
* of {@link ArchiveEntry} by {@link #getResources()}.
7980
* </ul>
@@ -82,13 +83,13 @@ public abstract class AbstractArchiver
8283

8384
private boolean includeEmptyDirs = true;
8485

85-
private int fileMode = -1;
86+
private int forcedFileMode = -1; // Will always be used
8687

87-
private int directoryMode = -1;
88+
private int forcedDirectoryMode = -1; // Will always be used
8889

89-
private int defaultFileMode = -1;
90+
private int defaultFileMode = -1; // Optionally used if a value is needed
9091

91-
private int defaultDirectoryMode = -1;
92+
private int defaultDirectoryMode = -1; // Optionally used if a value is needed
9293

9394
private boolean forced = true;
9495

@@ -101,7 +102,8 @@ public abstract class AbstractArchiver
101102
// On lunix-like systems, we replace windows backslashes with forward slashes
102103
private final boolean replacePathSlashesToJavaPaths = File.separatorChar == '/';
103104

104-
private final List<Closeable> closeables = new ArrayList<Closeable>( );
105+
private final List<Closeable> closeables = new ArrayList<Closeable>();
106+
105107
/**
106108
* since 2.2 is on by default
107109
*
@@ -112,6 +114,36 @@ public abstract class AbstractArchiver
112114
// contextualized.
113115
private ArchiverManager archiverManager;
114116

117+
private static class AddedResourceCollection
118+
{
119+
private final PlexusIoResourceCollection resources;
120+
121+
private final int forcedFileMode;
122+
123+
private final int forcedDirectoryMode;
124+
125+
public AddedResourceCollection( PlexusIoResourceCollection resources, int forcedFileMode, int forcedDirMode )
126+
{
127+
this.resources = resources;
128+
this.forcedFileMode = forcedFileMode;
129+
this.forcedDirectoryMode = forcedDirMode;
130+
}
131+
132+
private int maybeOverridden( int suggestedMode, boolean isDir )
133+
{
134+
if ( isDir )
135+
{
136+
return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode;
137+
}
138+
else
139+
{
140+
return forcedFileMode >= 0 ? forcedFileMode : suggestedMode;
141+
142+
}
143+
}
144+
145+
}
146+
115147
/**
116148
* @since 1.1
117149
*/
@@ -138,11 +170,11 @@ public final void setFileMode( final int mode )
138170
{
139171
if ( mode >= 0 )
140172
{
141-
fileMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.FILE_FLAG;
173+
forcedFileMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.FILE_FLAG;
142174
}
143175
else
144176
{
145-
fileMode = -1;
177+
forcedFileMode = -1;
146178
}
147179
}
148180

@@ -153,12 +185,12 @@ public final void setDefaultFileMode( final int mode )
153185

154186
public final int getOverrideFileMode()
155187
{
156-
return fileMode;
188+
return forcedFileMode;
157189
}
158190

159191
public final int getFileMode()
160192
{
161-
if ( fileMode < 0 )
193+
if ( forcedFileMode < 0 )
162194
{
163195
if ( defaultFileMode < 0 )
164196
{
@@ -168,7 +200,7 @@ public final int getFileMode()
168200
return defaultFileMode;
169201
}
170202

171-
return fileMode;
203+
return forcedFileMode;
172204
}
173205

174206
public final int getDefaultFileMode()
@@ -188,11 +220,11 @@ public final void setDirectoryMode( final int mode )
188220
{
189221
if ( mode >= 0 )
190222
{
191-
directoryMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.DIR_FLAG;
223+
forcedDirectoryMode = ( mode & UnixStat.PERM_MASK ) | UnixStat.DIR_FLAG;
192224
}
193225
else
194226
{
195-
directoryMode = -1;
227+
forcedDirectoryMode = -1;
196228
}
197229
}
198230

@@ -203,12 +235,12 @@ public final void setDefaultDirectoryMode( final int mode )
203235

204236
public final int getOverrideDirectoryMode()
205237
{
206-
return directoryMode;
238+
return forcedDirectoryMode;
207239
}
208240

209241
public final int getDirectoryMode()
210242
{
211-
if ( directoryMode < 0 )
243+
if ( forcedDirectoryMode < 0 )
212244
{
213245
if ( defaultDirectoryMode < 0 )
214246
{
@@ -218,7 +250,7 @@ public final int getDirectoryMode()
218250
return defaultDirectoryMode;
219251
}
220252

221-
return directoryMode;
253+
return forcedDirectoryMode;
222254
}
223255

224256
public final int getDefaultDirectoryMode()
@@ -338,8 +370,8 @@ public void addSymlink( String symlinkName, String symlinkDestination )
338370
public void addSymlink( String symlinkName, int permissions, String symlinkDestination )
339371
throws ArchiverException
340372
{
341-
doAddResource( ArchiveEntry.createSymlinkEntry( symlinkName, permissions, symlinkDestination,
342-
getDirectoryMode() ) );
373+
doAddResource(
374+
ArchiveEntry.createSymlinkEntry( symlinkName, permissions, symlinkDestination, getDirectoryMode() ) );
343375
}
344376

345377
protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource, final String destFileName,
@@ -353,35 +385,49 @@ protected ArchiveEntry asArchiveEntry( @Nonnull final PlexusIoResource resource,
353385

354386
if ( resource.isFile() )
355387
{
356-
return ArchiveEntry.createFileEntry( destFileName, resource, permissions, collection,
357-
getDirectoryMode() );
388+
return ArchiveEntry.createFileEntry( destFileName, resource, permissions, collection, getDirectoryMode() );
358389
}
359390
else
360391
{
361392
return ArchiveEntry.createDirectoryEntry( destFileName, resource, permissions, getDirectoryMode() );
362393
}
363394
}
364395

365-
protected ArchiveEntry asArchiveEntry( final PlexusIoResourceCollection collection,
366-
final PlexusIoResource resource )
396+
private int maybeOverridden( int suggestedMode, boolean isDir )
397+
{
398+
if ( isDir )
399+
{
400+
return forcedDirectoryMode >= 0 ? forcedDirectoryMode : suggestedMode;
401+
}
402+
else
403+
{
404+
return forcedFileMode >= 0 ? forcedFileMode : suggestedMode;
405+
406+
}
407+
}
408+
409+
private ArchiveEntry asArchiveEntry( final AddedResourceCollection collection, final PlexusIoResource resource )
367410
throws ArchiverException
368411
{
369-
final String destFileName = collection.getName( resource );
412+
final String destFileName = collection.resources.getName( resource );
370413

371-
int permissions = -1;
372-
if ( resource instanceof ResourceAttributeSupplier)
414+
int fromResource = -1;
415+
if ( resource instanceof ResourceAttributeSupplier )
373416
{
374417
final PlexusIoResourceAttributes attrs = ( (ResourceAttributeSupplier) resource ).getAttributes();
375418

376419
if ( attrs != null )
377420
{
378-
permissions = attrs.getOctalMode();
421+
fromResource = attrs.getOctalMode();
379422
}
380423
}
381424

382-
return asArchiveEntry( resource, destFileName, permissions, collection );
425+
return asArchiveEntry( resource, destFileName,
426+
collection.maybeOverridden( fromResource, resource.isDirectory() ),
427+
collection.resources );
383428
}
384429

430+
385431
public void addResource( final PlexusIoResource resource, final String destFileName, final int permissions )
386432
throws ArchiverException
387433
{
@@ -426,7 +472,7 @@ public ResourceIterator getResources()
426472
{
427473
private final Iterator addedResourceIter = resources.iterator();
428474

429-
private PlexusIoResourceCollection currentResourceCollection;
475+
private AddedResourceCollection currentResourceCollection;
430476

431477
private Iterator ioResourceIter;
432478

@@ -449,13 +495,13 @@ public boolean hasNext()
449495
{
450496
nextEntry = (ArchiveEntry) o;
451497
}
452-
else if ( o instanceof PlexusIoResourceCollection )
498+
else if ( o instanceof AddedResourceCollection )
453499
{
454-
currentResourceCollection = (PlexusIoResourceCollection) o;
500+
currentResourceCollection = (AddedResourceCollection) o;
455501

456502
try
457503
{
458-
ioResourceIter = currentResourceCollection.getResources();
504+
ioResourceIter = currentResourceCollection.resources.getResources();
459505
}
460506
catch ( final IOException e )
461507
{
@@ -492,7 +538,7 @@ else if ( o instanceof PlexusIoResourceCollection )
492538
}
493539
}
494540

495-
if ( nextEntry != null && seenEntries.contains( normalizedForDuplicateCheck(nextEntry) ))
541+
if ( nextEntry != null && seenEntries.contains( normalizedForDuplicateCheck( nextEntry ) ) )
496542
{
497543
final String path = nextEntry.getName();
498544

@@ -540,7 +586,7 @@ public ArchiveEntry next()
540586
final ArchiveEntry next = nextEntry;
541587
nextEntry = null;
542588

543-
seenEntries.add( normalizedForDuplicateCheck(next) );
589+
seenEntries.add( normalizedForDuplicateCheck( next ) );
544590

545591
return next;
546592
}
@@ -550,8 +596,9 @@ public void remove()
550596
throw new UnsupportedOperationException( "Does not support iterator" );
551597
}
552598

553-
private String normalizedForDuplicateCheck(ArchiveEntry entry){
554-
return entry.getName().replace( '\\', '/' );
599+
private String normalizedForDuplicateCheck( ArchiveEntry entry )
600+
{
601+
return entry.getName().replace( '\\', '/' );
555602
}
556603

557604
};
@@ -654,8 +701,9 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
654701
"Error adding archived file-set. PlexusIoResourceCollection not found for: " + archiveFile, e );
655702
}
656703

657-
if (resources instanceof EncodingSupported ) {
658-
((EncodingSupported)resources).setEncoding( charset );
704+
if ( resources instanceof EncodingSupported )
705+
{
706+
( (EncodingSupported) resources ).setEncoding( charset );
659707
}
660708

661709
if ( resources instanceof PlexusIoArchivedResourceCollection )
@@ -702,11 +750,12 @@ protected PlexusIoResourceCollection asResourceCollection( final ArchivedFileSet
702750
public void addResources( final PlexusIoResourceCollection collection )
703751
throws ArchiverException
704752
{
705-
doAddResource( collection );
753+
doAddResource( new AddedResourceCollection( collection, forcedFileMode, forcedDirectoryMode ) );
706754
}
707755

708-
private void doAddResource(Object item){
709-
resources.add( item);
756+
private void doAddResource( Object item )
757+
{
758+
resources.add( item );
710759
}
711760

712761
public void addArchivedFileSet( final ArchivedFileSet fileSet )
@@ -838,11 +887,11 @@ protected boolean isUptodate()
838887
{
839888
l = ( (ArchiveEntry) o ).getResource().getLastModified();
840889
}
841-
else if ( o instanceof PlexusIoResourceCollection )
890+
else if ( o instanceof AddedResourceCollection )
842891
{
843892
try
844893
{
845-
l = ( (PlexusIoResourceCollection) o ).getLastModified();
894+
l = ( (AddedResourceCollection) o ).resources.getLastModified();
846895
}
847896
catch ( final IOException e )
848897
{
@@ -967,11 +1016,15 @@ protected void validate()
9671016

9681017
protected abstract String getArchiveType();
9691018

970-
private void addCloseable(Object maybeCloseable){
971-
if (maybeCloseable instanceof Closeable)
1019+
private void addCloseable( Object maybeCloseable )
1020+
{
1021+
if ( maybeCloseable instanceof Closeable )
1022+
{
9721023
closeables.add( (Closeable) maybeCloseable );
1024+
}
9731025

9741026
}
1027+
9751028
private void closeIterators()
9761029
{
9771030
for ( Closeable closeable : closeables )
@@ -980,6 +1033,7 @@ private void closeIterators()
9801033
}
9811034

9821035
}
1036+
9831037
protected abstract void close()
9841038
throws IOException;
9851039

0 commit comments

Comments
 (0)