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.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          // required for mojo lookups to work
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                  // TODO Auto-generated catch block
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  }