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       */
58      @Parameter( property = "maven.test.skip" )
59      private boolean skip;
60  
61      /**
62       * {@inheritDoc}
63       */
64      public void execute()
65          throws MojoExecutionException
66      {
67          if ( skip )
68          {
69              getLog().info( "Not copying test resources" );
70          }
71          else
72          {
73              super.execute();
74          }
75      }
76  
77      public File getOutputDirectory()
78      {
79          return outputDirectory;
80      }
81  
82      public void setOutputDirectory( File outputDirectory )
83      {
84          this.outputDirectory = outputDirectory;
85      }
86  
87      public List<Resource> getResources()
88      {
89          return resources;
90      }
91  
92      public void setResources( List<Resource> resources )
93      {
94          this.resources = resources;
95      }
96  
97  }