|
| 1 | +package org.codehaus.plexus.archiver.jar; |
| 2 | + |
| 3 | +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; |
| 4 | +import org.apache.commons.compress.archivers.zip.ZipFile; |
| 5 | +import org.codehaus.plexus.PlexusTestCase; |
| 6 | +import org.codehaus.plexus.archiver.Archiver; |
| 7 | +import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet; |
| 8 | +import org.codehaus.plexus.components.io.filemappers.IdentityMapper; |
| 9 | +import org.codehaus.plexus.components.io.functions.InputStreamTransformer; |
| 10 | +import org.codehaus.plexus.components.io.resources.PlexusIoResource; |
| 11 | +import org.junit.Test; |
| 12 | + |
| 13 | +import javax.annotation.Nonnull; |
| 14 | +import java.io.File; |
| 15 | +import java.io.IOException; |
| 16 | +import java.io.InputStream; |
| 17 | +import java.nio.charset.Charset; |
| 18 | +import java.util.Enumeration; |
| 19 | + |
| 20 | +public class UnpackJarTest extends PlexusTestCase |
| 21 | +{ |
| 22 | + |
| 23 | + public static final String[] DEFAULT_INCLUDES_ARRAY = { "**/*" }; |
| 24 | + |
| 25 | + static class IdentityTransformer |
| 26 | + implements InputStreamTransformer |
| 27 | + { |
| 28 | + IdentityTransformer() |
| 29 | + { |
| 30 | + } |
| 31 | + |
| 32 | + @Nonnull |
| 33 | + public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream ) |
| 34 | + throws IOException |
| 35 | + { |
| 36 | + return inputStream; |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + public void test_dependency_sets_depSet_unpacked_rdonly() |
| 42 | + throws Exception |
| 43 | + { |
| 44 | + if (true) return; |
| 45 | + File src = new File("src/test/resources/unpack_issue.jar"); |
| 46 | + assertTrue( src.exists()); |
| 47 | + DefaultArchivedFileSet afs = DefaultArchivedFileSet.archivedFileSet( src ); |
| 48 | + afs.setIncludes( DEFAULT_INCLUDES_ARRAY ); |
| 49 | + afs.setExcludes( null ); |
| 50 | + afs.setPrefix( "child-1/" ); |
| 51 | + afs.setStreamTransformer( new IdentityTransformer() ); |
| 52 | + Archiver archiver = (Archiver)lookup( Archiver.ROLE, "dir" ); |
| 53 | + archiver.setDefaultDirectoryMode( 0555 ); |
| 54 | + archiver.setDirectoryMode( 0555 ); // causes permission denied |
| 55 | + archiver.setDestFile( new File( "target/depset_unpack" ) ); |
| 56 | + archiver.addArchivedFileSet( afs, Charset.forName("UTF-8" )); |
| 57 | + archiver.createArchive(); |
| 58 | + assertTrue( new File("target/depset_unpack/child-1/META-INF/MANIFEST.MF").exists()); |
| 59 | + } |
| 60 | +} |
0 commit comments