View Javadoc
1   package org.apache.maven.plugin.dependency;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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          // required for mojo lookups to work
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                  // TODO Auto-generated catch block
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  }