View Javadoc
1   package org.codehaus.plexus.archiver;
2   
3   import java.io.File;
4   import java.util.jar.JarFile;
5   import org.codehaus.plexus.PlexusTestCase;
6   import org.codehaus.plexus.archiver.jar.JarArchiver;
7   
8   /**
9    * @author Jason van Zyl
10   */
11  public class DotDirectiveArchiveFinalizerTest
12      extends PlexusTestCase
13  {
14  
15      public void testDotDirectiveArchiveFinalizer()
16          throws Exception
17      {
18          DotDirectiveArchiveFinalizer ddaf =
19              new DotDirectiveArchiveFinalizer( new File( getBasedir(), "src/test/dotfiles" ) );
20  
21          JarArchiver archiver = new JarArchiver();
22  
23          File jarFile = new File( getBasedir(), "target/dotfiles.jar" );
24  
25          archiver.setDestFile( jarFile );
26  
27          archiver.addArchiveFinalizer( ddaf );
28  
29          archiver.createArchive();
30  
31          JarFile jar = new JarFile( jarFile );
32  
33          assertNotNull( jar.getEntry( "LICENSE.txt" ) );
34  
35          assertNotNull( jar.getEntry( "NOTICE.txt" ) );
36  
37          assertNotNull( jar.getEntry( "META-INF/maven/LICENSE.txt" ) );
38  
39          assertNotNull( jar.getEntry( "META-INF/maven/NOTICE.txt" ) );
40      }
41  
42      public void testDefaultDotDirectiveBehaviour()
43          throws Exception
44      {
45          File dotFileDirectory = new File( getBasedir(), "src/test/dotfiles" );
46  
47          JarArchiver archiver = new JarArchiver();
48  
49          archiver.setDotFileDirectory( dotFileDirectory );
50  
51          File jarFile = new File( getBasedir(), "target/default-dotfiles.jar" );
52  
53          archiver.setDestFile( jarFile );
54  
55          archiver.createArchive();
56  
57          JarFile jar = new JarFile( jarFile );
58  
59          assertNotNull( jar.getEntry( "LICENSE.txt" ) );
60  
61          assertNotNull( jar.getEntry( "NOTICE.txt" ) );
62  
63          assertNotNull( jar.getEntry( "META-INF/maven/LICENSE.txt" ) );
64  
65          assertNotNull( jar.getEntry( "META-INF/maven/NOTICE.txt" ) );
66      }
67  
68  }