View Javadoc
1   package org.codehaus.plexus.archiver.jar;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.io.InputStream;
6   import java.nio.charset.Charset;
7   import javax.annotation.Nonnull;
8   import org.codehaus.plexus.PlexusTestCase;
9   import org.codehaus.plexus.archiver.Archiver;
10  import org.codehaus.plexus.archiver.util.ArchiveEntryUtils;
11  import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet;
12  import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
13  import org.codehaus.plexus.components.io.resources.PlexusIoResource;
14  
15  public class DirectoryArchiverUnpackJarTest
16      extends PlexusTestCase
17  {
18  
19      public static final String[] DEFAULT_INCLUDES_ARRAY =
20      {
21          "**/*"
22      };
23  
24      static class IdentityTransformer
25          implements InputStreamTransformer
26      {
27  
28          IdentityTransformer()
29          {
30          }
31  
32          @Nonnull
33          @Override
34          public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream )
35              throws IOException
36          {
37              return inputStream;
38          }
39  
40      }
41  
42      public void test_dependency_sets_depSet_unpacked_rdonly()
43          throws Exception
44      {
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 if bug is not fixed.
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          // make them writeable or mvn clean will fail
61          ArchiveEntryUtils.chmod( new File( "target/depset_unpack/child-1/META-INF" ), 0777 );
62          ArchiveEntryUtils.chmod( new File( "target/depset_unpack/child-1/META-INF/maven" ), 0777 );
63          ArchiveEntryUtils.chmod( new File( "target/depset_unpack/child-1/META-INF/maven/test" ), 0777 );
64          ArchiveEntryUtils.chmod( new File( "target/depset_unpack/child-1/META-INF/maven/test/child1" ), 0777 );
65          ArchiveEntryUtils.chmod( new File( "target/depset_unpack/child-1/assembly-resources" ), 0777 );
66      }
67  
68  }