View Javadoc
1   package org.apache.maven.plugin.resources;
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 org.apache.maven.model.Resource;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugins.annotations.LifecyclePhase;
25  import org.apache.maven.plugins.annotations.Mojo;
26  import org.apache.maven.plugins.annotations.Parameter;
27  
28  import java.io.File;
29  import java.util.List;
30  
31  /**
32   * Copy resources for the test source code to the test output directory.
33   * Always uses the project.build.testResources element to specify the resources to copy.
34   *
35   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
36   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
37   */
38  @Mojo( name = "testResources", defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES, threadSafe = true )
39  public class TestResourcesMojo
40      extends ResourcesMojo
41  {
42      /**
43       * The output directory into which to copy the resources.
44       */
45      @Parameter( defaultValue = "${project.build.testOutputDirectory}", required = true )
46      private File outputDirectory;
47  
48      /**
49       * The list of resources we want to transfer.
50       */
51      @Parameter( defaultValue = "${project.testResources}", required = true, readonly = false )
52      private List<Resource> resources;
53  
54      /**
55       * Set this to 'true' to bypass copying of test resources.
56       * Its use is NOT RECOMMENDED, but quite convenient on occasion.
57       * @since 2.6
58       */
59      @Parameter( property = "maven.test.skip" )
60      private boolean skip;
61  
62      /**
63       * {@inheritDoc}
64       */
65      public void execute()
66          throws MojoExecutionException
67      {
68          if ( skip )
69          {
70              getLog().info( "Not copying test resources" );
71          }
72          else
73          {
74              super.execute();
75          }
76      }
77  
78      public File getOutputDirectory()
79      {
80          return outputDirectory;
81      }
82  
83      public void setOutputDirectory( File outputDirectory )
84      {
85          this.outputDirectory = outputDirectory;
86      }
87  
88      public List<Resource> getResources()
89      {
90          return resources;
91      }
92  
93      public void setResources( List<Resource> resources )
94      {
95          this.resources = resources;
96      }
97  
98  }