Skip to content

Commit 5033cd0

Browse files
committed
PLXCOMP-232. Unpacking .tar.gz fails
1 parent 6d5f744 commit 5033cd0

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
122 KB
Binary file not shown.

src/test/jars/test.tar.gz

411 Bytes
Binary file not shown.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.codehaus.plexus.archiver.tar;
2+
3+
import org.codehaus.plexus.PlexusTestCase;
4+
import org.codehaus.plexus.archiver.UnArchiver;
5+
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
6+
import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
7+
import org.codehaus.plexus.util.FileUtils;
8+
9+
import java.io.File;
10+
import java.lang.reflect.Method;
11+
12+
/**
13+
* @author <a href="mailto:viktor@jv-ration.com">Viktor Sadovnikov</a>
14+
* @version $Revision$ $Date$
15+
*/
16+
public class TarUnArchiverTest extends PlexusTestCase
17+
{
18+
19+
private void runUnarchiver( FileSelector[] selectors, boolean[] results )
20+
throws Exception
21+
{
22+
String s = "target/tar-unarchiver-tests";
23+
24+
File testJar = new File( getBasedir(), "src/test/jars/test.tar.gz" );
25+
26+
File outputDirectory = new File( getBasedir(), s );
27+
28+
TarUnArchiver tarUn = (TarUnArchiver) lookup( UnArchiver.ROLE, "tar.gz" );
29+
tarUn.setSourceFile(testJar);
30+
tarUn.setDestDirectory(outputDirectory);
31+
tarUn.setFileSelectors(selectors);
32+
33+
FileUtils.deleteDirectory( outputDirectory );
34+
35+
tarUn.extract();
36+
37+
assertFileExistance( s, "/resources/artifactId/test.properties", results[0]);
38+
assertFileExistance( s, "/resources/artifactId/directory/test.properties", results[1]);
39+
assertFileExistance( s, "/META-INF/MANIFEST.MF", results[2]);
40+
41+
}
42+
43+
private void assertFileExistance( String s, String file, boolean exists ) {
44+
File f0 = new File( getBasedir(), s + file );
45+
assertEquals( String.format("Did %s expect to find %s file", exists ? "" : "NOT", f0.getAbsoluteFile()), exists, f0.exists() );
46+
}
47+
48+
public void testExtractingADirectoryFromAJarFile()
49+
throws Exception
50+
{
51+
runUnarchiver( null, new boolean[]{ true, true, false } );
52+
runUnarchiver( null, new boolean[]{ true, true, true } );
53+
}
54+
55+
public void testSelectors()
56+
throws Exception
57+
{
58+
IncludeExcludeFileSelector fileSelector = new IncludeExcludeFileSelector();
59+
runUnarchiver( new FileSelector[]{ fileSelector }, new boolean[]{ true, true, true } );
60+
fileSelector.setExcludes( new String[]{ "**/test.properties" } );
61+
runUnarchiver( new FileSelector[]{ fileSelector }, new boolean[]{ false, false, true } );
62+
fileSelector.setIncludes( new String[]{ "**/test.properties" } );
63+
fileSelector.setExcludes( null );
64+
runUnarchiver( new FileSelector[]{ fileSelector }, new boolean[]{ true, true, false } );
65+
fileSelector.setExcludes( new String[]{ "resources/artifactId/directory/test.properties" } );
66+
runUnarchiver( new FileSelector[]{ fileSelector }, new boolean[]{ true, false, false } );
67+
}
68+
}

0 commit comments

Comments
 (0)