1 package org.apache.maven.plugins.dependency;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
27 import org.apache.maven.plugins.dependency.testUtils.DependencyTestUtils;
28 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
29
30 public abstract class AbstractDependencyMojoTestCase
31 extends AbstractMojoTestCase
32 {
33
34 protected File testDir;
35
36 protected DependencyArtifactStubFactory stubFactory;
37
38 public AbstractDependencyMojoTestCase()
39 {
40 super();
41 }
42
43 protected void setUp( String testDirStr, boolean createFiles )
44 throws Exception
45 {
46 setUp( testDirStr, createFiles, true );
47 }
48
49 protected void setUp( String testDirStr, boolean createFiles, boolean flattenedPath )
50 throws Exception
51 {
52
53 super.setUp();
54 testDir = new File( getBasedir(), "target" + File.separatorChar + "unit-tests" + File.separatorChar + testDirStr
55 + File.separatorChar );
56 DependencyTestUtils.removeDirectory( testDir );
57 assertFalse( testDir.exists() );
58
59 stubFactory = new DependencyArtifactStubFactory( this.testDir, createFiles, flattenedPath );
60 }
61
62 protected void tearDown()
63 {
64 if ( testDir != null )
65 {
66 try
67 {
68 DependencyTestUtils.removeDirectory( testDir );
69 }
70 catch ( IOException e )
71 {
72
73 e.printStackTrace();
74 fail( "Trying to remove directory:" + testDir + "\r\n" + e.toString() );
75 }
76 assertFalse( testDir.exists() );
77
78 testDir = null;
79 }
80
81 stubFactory = null;
82 }
83
84 protected void copyFile( AbstractDependencyMojo mojo, File artifact, File destFile )
85 throws MojoExecutionException
86 {
87 mojo.copyFile( artifact, destFile );
88 }
89 }