1 package org.apache.maven.plugin.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.artifact.resolver.ArtifactResolver;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.dependency.testUtils.DependencyArtifactStubFactory;
28 import org.apache.maven.plugin.dependency.testUtils.DependencyTestUtils;
29 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
30
31 public abstract class AbstractDependencyMojoTestCase
32 extends AbstractMojoTestCase
33 {
34
35 protected File testDir;
36
37 protected DependencyArtifactStubFactory stubFactory;
38
39 public AbstractDependencyMojoTestCase()
40 {
41 super();
42 }
43
44 protected void setUp( String testDirStr, boolean createFiles )
45 throws Exception
46 {
47
48 super.setUp();
49 testDir = new File( getBasedir(), "target" + File.separatorChar + "unit-tests" + File.separatorChar
50 + testDirStr + File.separatorChar );
51 DependencyTestUtils.removeDirectory( testDir );
52 assertFalse( testDir.exists() );
53
54 stubFactory = new DependencyArtifactStubFactory( this.testDir, createFiles );
55
56 }
57
58 protected void tearDown()
59 {
60 if ( testDir != null )
61 {
62 try
63 {
64 DependencyTestUtils.removeDirectory( testDir );
65 }
66 catch ( IOException e )
67 {
68
69 e.printStackTrace();
70 fail( "Trying to remove directory:" + testDir + "\r\n" + e.toString() );
71 }
72 assertFalse( testDir.exists() );
73
74 testDir = null;
75 }
76
77 stubFactory = null;
78 }
79
80 protected void setResolver( AbstractDependencyMojo mojo, ArtifactResolver resolver )
81 {
82 mojo.resolver = resolver;
83 }
84
85 protected void setSilent( AbstractDependencyMojo mojo, boolean silent )
86 {
87 mojo.silent = silent;
88 }
89
90 protected void copyFile( AbstractDependencyMojo mojo, File artifact, File destFile )
91 throws MojoExecutionException
92 {
93 mojo.copyFile( artifact, destFile );
94 }
95 }