View Javadoc
1   package org.apache.maven.archetype.common;
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 junit.framework.TestCase;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.apache.maven.archetype.metadata.FileSet;
28  
29  public class TestDefaultArchetypeFilesResolver
30      extends TestCase
31  {
32      public void testResourceFiltering()
33          throws Exception
34      {
35          FileSet fileSet = new FileSet();
36  
37          fileSet.addInclude( "**/*.java" );
38  
39          fileSet.setDirectory( "src/main/java" );
40          fileSet.setEncoding( "UTF-8" );
41          fileSet.setPackaged( true );
42          fileSet.setFiltered( true );
43  
44          List<String> archetypeResources = new ArrayList<>();
45  
46          archetypeResources.add( "pom.xml" );
47          archetypeResources.add( "App.java" );
48          archetypeResources.add( "src/main/c/App.c" );
49          archetypeResources.add( "src/main/java/App.java" );
50          archetypeResources.add( "src/main/java/inner/package/App2.java" );
51          archetypeResources.add( "src/main/mdo/App.mdo" );
52          archetypeResources.add( "src/main/resources/App.properties" );
53          archetypeResources.add( "src/main/resources/inner/dir/App2.properties" );
54          archetypeResources.add( "src/test/c/AppTest.c" );
55          archetypeResources.add( "src/test/java/AppTest.java" );
56          archetypeResources.add( "src/test/mdo/AppTest.mdo" );
57          archetypeResources.add( "src/test/resources/AppTest.properties" );
58  
59          System.out.println( "FileSet:" + fileSet );
60          System.out.println( "Resources:" + archetypeResources );
61  
62          ArchetypeFilesResolver resolver = new DefaultArchetypeFilesResolver();
63  
64          List<String> fileSetResources = resolver.filterFiles( "", fileSet, archetypeResources );
65  
66          System.out.println( "Result:" + fileSetResources );
67  
68          assertEquals( 2, fileSetResources.size() );
69      }
70  
71  }