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