View Javadoc

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