Skip to content

Commit 6151890

Browse files
plamentotevmichael-o
authored andcommitted
Upgrade Plexus IO to 3.0.0 and clean up legacy code
It may seem that there are lot of changes but actually most of them are: * Rename `Java7FileAttributes` to `FileAttributes`. In the new version of Plexus IO `FileAttributes` is replaced by `Java7FileAttributes` * Remove calls to `Java7Reflector.isAtLeastJava7()`. `Java7Reflector` is deleted from the new version of Plexus IO because now at least Java 7 is required The most significant change is made inside `ArchiveEntryUtils#chmod` -- now the Java version is at least 7 so together with the removal of the call to `Java7Reflector.isAtLeastJava7()` the legacy code is removed as well. Remove the `commons-io` dependency. Plexus IO 3.0.0 was updated to use `commons-io` 2.5 so there is no longer a need to override the transitive dependency.
1 parent e40aebc commit 6151890

File tree

11 files changed

+26
-170
lines changed

11 files changed

+26
-170
lines changed

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@
5656
<dependency>
5757
<groupId>org.codehaus.plexus</groupId>
5858
<artifactId>plexus-io</artifactId>
59-
<version>2.7.1</version>
60-
</dependency>
61-
<dependency>
62-
<!-- Upgrade to transitive dependency of 'plexus-io' which is JDK 5+ only. -->
63-
<groupId>commons-io</groupId>
64-
<artifactId>commons-io</artifactId>
65-
<version>2.5</version>
59+
<version>3.0.0</version>
6660
</dependency>
6761
<dependency>
6862
<groupId>org.apache.commons</groupId>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.codehaus.plexus.archiver.manager.ArchiverManager;
3636
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
3737
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
38-
import org.codehaus.plexus.components.io.attributes.Java7Reflector;
3938
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
4039
import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
4140
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection;
@@ -363,7 +362,7 @@ public void addFileSet( @Nonnull final FileSet fileSet )
363362

364363
private boolean isSymlinkSupported()
365364
{
366-
return Os.isFamily( Os.FAMILY_UNIX ) && Java7Reflector.isAtLeastJava7();
365+
return Os.isFamily( Os.FAMILY_UNIX );
367366
}
368367

369368
@Override

src/main/java/org/codehaus/plexus/archiver/bzip2/PlexusIoBzip2ResourceCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.HashMap;
88
import javax.annotation.Nonnull;
99
import javax.annotation.WillNotClose;
10-
import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
10+
import org.codehaus.plexus.components.io.attributes.FileAttributes;
1111
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
1212
import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
1313
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
@@ -42,7 +42,7 @@ InputStream getInputStream( File file )
4242

4343
@Override protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
4444
{
45-
return new Java7FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
45+
return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
4646
}
4747

4848
@Override

src/main/java/org/codehaus/plexus/archiver/gzip/PlexusIoGzipResourceCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.zip.GZIPInputStream;
99
import javax.annotation.Nonnull;
1010
import org.codehaus.plexus.archiver.util.Streams;
11-
import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
11+
import org.codehaus.plexus.components.io.attributes.FileAttributes;
1212
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
1313
import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
1414
import org.codehaus.plexus.util.IOUtil;
@@ -49,7 +49,7 @@ protected InputStream getInputStream( File file )
4949
protected PlexusIoResourceAttributes getAttributes( File file )
5050
throws IOException
5151
{
52-
return new Java7FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
52+
return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
5353
}
5454

5555
}

src/main/java/org/codehaus/plexus/archiver/resources/PlexusIoVirtualFileResource.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
import java.io.InputStream;
2121
import java.net.URL;
2222
import javax.annotation.Nonnull;
23-
import org.codehaus.plexus.components.io.attributes.Java7AttributeUtils;
24-
import org.codehaus.plexus.components.io.attributes.Java7Reflector;
23+
import org.codehaus.plexus.components.io.attributes.AttributeUtils;
2524
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
2625
import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
2726
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
@@ -106,14 +105,7 @@ public long getLastModified()
106105
{
107106
if ( file.exists() )
108107
{
109-
if ( Java7Reflector.isAtLeastJava7() )
110-
{
111-
return Java7AttributeUtils.getLastModified( getFile() );
112-
}
113-
else
114-
{
115-
return getFile().lastModified();
116-
}
108+
return AttributeUtils.getLastModified( getFile() );
117109
}
118110
else
119111
{

src/main/java/org/codehaus/plexus/archiver/snappy/PlexusIoSnappyResourceCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.HashMap;
88
import javax.annotation.Nonnull;
99
import javax.annotation.WillNotClose;
10-
import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
10+
import org.codehaus.plexus.components.io.attributes.FileAttributes;
1111
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
1212
import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
1313
import org.codehaus.plexus.util.IOUtil;
@@ -41,7 +41,7 @@ InputStream getInputStream( File file )
4141

4242
@Override protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
4343
{
44-
return new Java7FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
44+
return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
4545
}
4646

4747
@Override

src/main/java/org/codehaus/plexus/archiver/util/ArchiveEntryUtils.java

Lines changed: 4 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717

1818
import java.io.File;
1919
import java.io.IOException;
20-
import java.lang.reflect.Method;
2120
import org.codehaus.plexus.archiver.ArchiverException;
22-
import org.codehaus.plexus.components.io.attributes.Java7AttributeUtils;
23-
import org.codehaus.plexus.components.io.attributes.Java7Reflector;
21+
import org.codehaus.plexus.components.io.attributes.AttributeUtils;
2422
import org.codehaus.plexus.logging.Logger;
2523
import org.codehaus.plexus.util.Os;
26-
import org.codehaus.plexus.util.cli.CommandLineException;
27-
import org.codehaus.plexus.util.cli.CommandLineUtils;
28-
import org.codehaus.plexus.util.cli.Commandline;
2924

3025
@SuppressWarnings( "JavaDoc" )
3126
public final class ArchiveEntryUtils
@@ -68,80 +63,14 @@ public static void chmod( final File file, final int mode, final Logger logger,
6863
return;
6964
}
7065

71-
if ( Java7Reflector.isAtLeastJava7() )
72-
{
73-
try
74-
{
75-
Java7AttributeUtils.chmod( file, mode );
76-
return;
77-
}
78-
catch ( IOException e )
79-
{
80-
throw new ArchiverException( "Failed setting file attributes with java7+", e );
81-
}
82-
}
83-
84-
final String m = Integer.toOctalString( mode & 0xfff );
85-
86-
if ( useJvmChmod && !jvmFilePermAvailable )
87-
{
88-
useJvmChmod = false;
89-
}
90-
91-
if ( useJvmChmod )
92-
{
93-
applyPermissionsWithJvm( file, m, logger );
94-
return;
95-
}
96-
9766
try
9867
{
99-
final Commandline commandline = new Commandline();
100-
101-
commandline.setWorkingDirectory( file.getParentFile().getAbsolutePath() );
102-
103-
if ( logger.isDebugEnabled() )
104-
{
105-
logger.debug( file + ": mode " + Integer.toOctalString( mode ) + ", chmod " + m );
106-
}
107-
108-
commandline.setExecutable( "chmod" );
109-
110-
commandline.createArg().setValue( m );
111-
112-
final String path = file.getAbsolutePath();
113-
114-
commandline.createArg().setValue( path );
115-
116-
// commenting this debug statement, since it can produce VERY verbose output...
117-
// this method is called often during archive creation.
118-
// logger.debug( "Executing:\n\n" + commandline.toString() + "\n\n" );
119-
final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
120-
121-
final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
122-
123-
final int exitCode = CommandLineUtils.executeCommandLine( commandline, stderr, stdout );
124-
125-
if ( exitCode != 0 )
126-
{
127-
logger.warn( "-------------------------------" );
128-
logger.warn( "Standard error:" );
129-
logger.warn( "-------------------------------" );
130-
logger.warn( stderr.getOutput() );
131-
logger.warn( "-------------------------------" );
132-
logger.warn( "Standard output:" );
133-
logger.warn( "-------------------------------" );
134-
logger.warn( stdout.getOutput() );
135-
logger.warn( "-------------------------------" );
136-
137-
throw new ArchiverException( "chmod exit code was: " + exitCode );
138-
}
68+
AttributeUtils.chmod( file, mode );
13969
}
140-
catch ( final CommandLineException e )
70+
catch ( IOException e )
14171
{
142-
throw new ArchiverException( "Error while executing chmod.", e );
72+
throw new ArchiverException( "Failed setting file attributes", e );
14373
}
144-
14574
}
14675

14776
/**
@@ -159,45 +88,4 @@ public static void chmod( final File file, final int mode, final Logger logger )
15988
chmod( file, mode, logger, Boolean.getBoolean( "useJvmChmod" ) && jvmFilePermAvailable );
16089
}
16190

162-
private static void applyPermissionsWithJvm( final File file, final String mode, final Logger logger )
163-
throws ArchiverException
164-
{
165-
final FilePermission filePermission;
166-
try
167-
{
168-
filePermission = FilePermissionUtils.getFilePermissionFromMode( mode, logger );
169-
}
170-
catch ( IllegalArgumentException e )
171-
{
172-
throw new ArchiverException( "Problem getting permission from mode for " + file.getPath(), e );
173-
}
174-
175-
Method method;
176-
try
177-
{
178-
method = File.class.getMethod( "setReadable", Boolean.TYPE, Boolean.TYPE );
179-
180-
method.invoke( file,
181-
filePermission.isReadable(),
182-
filePermission.isOwnerOnlyReadable() );
183-
184-
method = File.class.getMethod( "setExecutable", Boolean.TYPE, Boolean.TYPE );
185-
186-
method.invoke( file,
187-
filePermission.isExecutable(),
188-
filePermission.isOwnerOnlyExecutable() );
189-
190-
method = File.class.getMethod( "setWritable", Boolean.TYPE, Boolean.TYPE );
191-
192-
method.invoke( file,
193-
filePermission.isWritable(),
194-
filePermission.isOwnerOnlyWritable() );
195-
}
196-
catch ( final Exception e )
197-
{
198-
logger.error( "error calling dynamically file permissons with jvm " + e.getMessage(), e );
199-
throw new ArchiverException( "error calling dynamically file permissons with jvm " + e.getMessage(), e );
200-
}
201-
}
202-
20391
}

src/main/java/org/codehaus/plexus/archiver/xz/PlexusIoXZResourceCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.IOException;
2121
import java.io.InputStream;
2222
import java.util.HashMap;
23-
import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
23+
import org.codehaus.plexus.components.io.attributes.FileAttributes;
2424
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
2525
import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
2626
import org.codehaus.plexus.util.IOUtil;
@@ -35,7 +35,7 @@ public class PlexusIoXZResourceCollection extends PlexusIoCompressedFileResource
3535
@Override
3636
protected PlexusIoResourceAttributes getAttributes( File file ) throws IOException
3737
{
38-
return new Java7FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
38+
return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
3939
}
4040

4141
@Override

src/test/java/org/codehaus/plexus/archiver/tar/TarFileAttributesTest.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.codehaus.plexus.archiver.Archiver;
1010
import org.codehaus.plexus.archiver.UnArchiver;
1111
import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet;
12-
import org.codehaus.plexus.components.io.attributes.Java7Reflector;
1312
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
1413
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
1514
import org.codehaus.plexus.util.FileUtils;
@@ -141,10 +140,7 @@ public void testUseAttributesFromTarArchiveInputInTarArchiverOutput()
141140
PlexusIoResourceAttributes fileAttributes =
142141
PlexusIoResourceAttributeUtils.getFileAttributes( new File( tempTarDir, tempFile.getName() ) );
143142

144-
final int expected = Java7Reflector.isAtLeastJava7() ? 0660 : 0644;
145-
146-
assertEquals( "This test will fail if your umask is not X2X (or more)",
147-
expected, fileAttributes.getOctalMode() );
143+
assertEquals( 0660, fileAttributes.getOctalMode() );
148144

149145
}
150146

@@ -207,10 +203,7 @@ public void testUseDetectedFileAttributes()
207203

208204
fileAttributes = PlexusIoResourceAttributeUtils.getFileAttributes( new File( tempTarDir, tempFile.getName() ) );
209205

210-
final int expected = Java7Reflector.isAtLeastJava7() ? 0440 : 0444;
211-
212-
assertEquals( "This test will fail if your umask is not X2X (or more)",
213-
expected, fileAttributes.getOctalMode() );
206+
assertEquals( 0440, fileAttributes.getOctalMode() );
214207

215208
}
216209

@@ -275,10 +268,7 @@ public void testOverrideDetectedFileAttributes()
275268
PlexusIoResourceAttributes fileAttributes =
276269
PlexusIoResourceAttributeUtils.getFileAttributes( new File( tempTarDir, tempFile.getName() ) );
277270

278-
final int expected = Java7Reflector.isAtLeastJava7() ? 0660 : 0644;
279-
280-
assertEquals( "This test will fail if your umask is not X2X (or more)",
281-
expected, fileAttributes.getOctalMode() );
271+
assertEquals( 0660, fileAttributes.getOctalMode() );
282272

283273
}
284274

@@ -345,9 +335,7 @@ public void testOverrideDetectedFileAttributesUsingFileMode()
345335
PlexusIoResourceAttributes fileAttributes =
346336
PlexusIoResourceAttributeUtils.getFileAttributes( new File( tempTarDir, tempFile.getName() ) );
347337

348-
final int expected = Java7Reflector.isAtLeastJava7() ? 0660 : 0644;
349-
assertEquals( "This test will fail if your umask is not X2X (or more)",
350-
expected, fileAttributes.getOctalMode() );
338+
assertEquals( 0660, fileAttributes.getOctalMode() );
351339

352340
}
353341

src/test/java/org/codehaus/plexus/archiver/util/ArchiveEntryUtilsTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.util.HashMap;
6-
import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
7-
import org.codehaus.plexus.components.io.attributes.Java7Reflector;
6+
import org.codehaus.plexus.components.io.attributes.FileAttributes;
87
import org.codehaus.plexus.logging.console.ConsoleLogger;
98
import org.codehaus.plexus.util.Os;
109
import junit.framework.TestCase;
@@ -27,10 +26,6 @@ public void testChmodForFileWithDollarPLXCOMP164() throws Exception
2726

2827
public void testChmodWithJava7() throws Exception
2928
{
30-
if ( !Java7Reflector.isAtLeastJava7() )
31-
{
32-
return; // Require at least java7
33-
}
3429
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
3530
{
3631
return;
@@ -44,8 +39,8 @@ public void testChmodWithJava7() throws Exception
4439

4540
private void assert0770( File temp ) throws IOException
4641
{
47-
Java7FileAttributes j7 = new Java7FileAttributes( temp, new HashMap<Integer, String>(),
48-
new HashMap<Integer, String>() );
42+
FileAttributes j7 = new FileAttributes( temp, new HashMap<Integer, String>(),
43+
new HashMap<Integer, String>() );
4944
assertTrue( j7.isGroupExecutable() );
5045
assertTrue( j7.isGroupReadable() );
5146
assertTrue( j7.isGroupWritable() );

src/test/java/org/codehaus/plexus/archiver/zip/ZipArchiverTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet;
5454
import org.codehaus.plexus.archiver.util.DefaultFileSet;
5555
import org.codehaus.plexus.archiver.util.Streams;
56-
import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
56+
import org.codehaus.plexus.components.io.attributes.FileAttributes;
5757
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
5858
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
5959
import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes;
@@ -520,7 +520,7 @@ public void testSymlinkZip()
520520
zipUnArchiver.setDestFile( output );
521521
zipUnArchiver.extract();
522522
File symDir = new File( "target/output/unzipped/plexus/src/symDir" );
523-
PlexusIoResourceAttributes fa = Java7FileAttributes.uncached( symDir );
523+
PlexusIoResourceAttributes fa = FileAttributes.uncached( symDir );
524524
assertTrue( fa.isSymbolicLink() );
525525
}
526526

@@ -541,7 +541,7 @@ public void testSymlinkFileSet()
541541
zipUnArchiver.setDestFile( output );
542542
zipUnArchiver.extract();
543543
File symDir = new File( output, "bzz/symDir" );
544-
PlexusIoResourceAttributes fa = Java7FileAttributes.uncached( symDir );
544+
PlexusIoResourceAttributes fa = FileAttributes.uncached( symDir );
545545
assertTrue( fa.isSymbolicLink() );
546546
}
547547

0 commit comments

Comments
 (0)