View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.resources;
20  
21  import java.io.File;
22  import java.util.List;
23  
24  import org.apache.maven.model.Resource;
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugins.annotations.LifecyclePhase;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  
30  /**
31   * Copy resources for the test source code to the test output directory.
32   * Always uses the project.build.testResources element to specify the resources to copy.
33   *
34   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
35   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
36   */
37  @Mojo(
38          name = "testResources",
39          defaultPhase = LifecyclePhase.PROCESS_TEST_RESOURCES,
40          requiresProject = true,
41          threadSafe = true)
42  public class TestResourcesMojo extends ResourcesMojo {
43      /**
44       * The output directory into which to copy the resources.
45       */
46      @Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true)
47      private File outputDirectory;
48  
49      /**
50       * The list of resources we want to transfer.
51       */
52      @Parameter(defaultValue = "${project.testResources}", required = true)
53      private List<Resource> resources;
54  
55      /**
56       * Set this to 'true' to bypass copying of test resources.
57       * Its use is NOT RECOMMENDED, but quite convenient on occasion.
58       * @since 2.6
59       */
60      @Parameter(property = "maven.test.skip", defaultValue = "false")
61      private boolean skip;
62  
63      /**
64       * {@inheritDoc}
65       */
66      public void execute() throws MojoExecutionException {
67          if (skip) {
68              getLog().info("Not copying test resources");
69          } else {
70              super.execute();
71          }
72      }
73  
74      /** {@inheritDoc} */
75      public File getOutputDirectory() {
76          return outputDirectory;
77      }
78  
79      /** {@inheritDoc} */
80      public void setOutputDirectory(File outputDirectory) {
81          this.outputDirectory = outputDirectory;
82      }
83  
84      /** {@inheritDoc} */
85      public List<Resource> getResources() {
86          return resources;
87      }
88  
89      /** {@inheritDoc} */
90      public void setResources(List<Resource> resources) {
91          this.resources = resources;
92      }
93  }