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.stub;
20  
21  import java.io.File;
22  
23  import org.apache.maven.model.Resource;
24  
25  public class MavenProjectResourcesStub extends MavenProjectBuildStub {
26  
27      private File baseDir;
28  
29      public MavenProjectResourcesStub(String id) throws Exception {
30          super(id);
31          setupResources();
32          setupTestResources();
33      }
34  
35      public void addInclude(String pattern) {
36          build.getResources().get(0).addInclude(pattern);
37      }
38  
39      public void addExclude(String pattern) {
40          build.getResources().get(0).addExclude(pattern);
41      }
42  
43      public void addTestInclude(String pattern) {
44          build.getTestResources().get(0).addInclude(pattern);
45      }
46  
47      public void addTestExclude(String pattern) {
48          build.getTestResources().get(0).addExclude(pattern);
49      }
50  
51      public void setTargetPath(String path) {
52          build.getResources().get(0).setTargetPath(path);
53      }
54  
55      public void setTestTargetPath(String path) {
56          build.getTestResources().get(0).setTargetPath(path);
57      }
58  
59      public void setDirectory(String dir) {
60          build.getResources().get(0).setDirectory(dir);
61      }
62  
63      public void setTestDirectory(String dir) {
64          build.getTestResources().get(0).setDirectory(dir);
65      }
66  
67      public void setResourceFiltering(int nIndex, boolean filter) {
68          if (build.getResources().size() > nIndex) {
69              build.getResources().get(nIndex).setFiltering(filter);
70          }
71      }
72  
73      private void setupResources() {
74          Resource resource = new Resource();
75  
76          // see MavenProjectBasicStub for details
77          // of getBasedir
78  
79          // setup default resources
80          resource.setDirectory(getBasedir().getPath() + "/src/main/resources");
81          resource.setFiltering(false);
82          resource.setTargetPath(null);
83          build.addResource(resource);
84      }
85  
86      private void setupTestResources() {
87          Resource resource = new Resource();
88  
89          // see MavenProjectBasicStub for details
90          // of getBasedir
91  
92          // setup default test resources
93          resource.setDirectory(getBasedir().getPath() + "/src/test/resources");
94          resource.setFiltering(false);
95          resource.setTargetPath(null);
96          build.addTestResource(resource);
97      }
98  
99      public File getBaseDir() {
100         return baseDir == null ? super.getBasedir() : baseDir;
101     }
102 
103     public void setBaseDir(File baseDir) {
104         this.baseDir = baseDir;
105     }
106 }