View Javadoc
1   package org.apache.maven.archetype.common.util;
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  /** @author <a href="mailto:brianf@apache.org">Brian Fox</a> */
28  public class TestListScanner
29      extends TestCase
30  {
31      public void testUnixPaths()
32      {
33          List<String> archetypeResources = new ArrayList<>();
34  
35          archetypeResources.add( "pom.xml" );
36          archetypeResources.add( "App.java" );
37          archetypeResources.add( "src/main/c/App.c" );
38          archetypeResources.add( "src/main/java/App.java" );
39          archetypeResources.add( "src/main/java/inner/package/App2.java" );
40          archetypeResources.add( "src/main/mdo/App.mdo" );
41          archetypeResources.add( "src/main/resources/App.properties" );
42          archetypeResources.add( "src/main/resources/inner/dir/App2.properties" );
43          archetypeResources.add( "src/test/c/AppTest.c" );
44          archetypeResources.add( "src/test/java/AppTest.java" );
45          archetypeResources.add( "src/test/mdo/AppTest.mdo" );
46          archetypeResources.add( "src/test/resources/AppTest.properties" );
47  
48          ListScanner scanner = new ListScanner();
49          scanner.setBasedir( "src/main/java" );
50          scanner.setIncludes( "**/*.java" );
51          scanner.setCaseSensitive( true );
52  
53          List<String> result = scanner.scan( archetypeResources );
54  
55          assertEquals( 2, result.size() );
56          assertTrue( result.contains( "src/main/java/App.java" ) );
57          assertTrue( result.contains( "src/main/java/inner/package/App2.java" ) );
58      }
59  
60      public void testWindowsPaths()
61      {
62          List<String> archetypeResources = new ArrayList<>();
63  
64          archetypeResources.add( "pom.xml" );
65          archetypeResources.add( "App.java" );
66          archetypeResources.add( "src\\main\\c\\App.c" );
67          archetypeResources.add( "src\\main\\java\\App.java" );
68          archetypeResources.add( "src\\main\\java\\inner\\package\\App2.java" );
69          archetypeResources.add( "src\\main\\mdo\\App.mdo" );
70          archetypeResources.add( "src\\main\\resources\\App.properties" );
71          archetypeResources.add( "src\\main\\resources\\inner\\dir\\App2.properties" );
72          archetypeResources.add( "src\\test\\c\\AppTest.c" );
73          archetypeResources.add( "src\\test\\java\\AppTest.java" );
74          archetypeResources.add( "src\\test\\mdo\\AppTest.mdo" );
75          archetypeResources.add( "src\\test\\resources\\AppTest.properties" );
76  
77          ListScanner scanner = new ListScanner();
78          scanner.setBasedir( "src\\main\\java" );
79          scanner.setIncludes( "**\\*.java" );
80          scanner.setCaseSensitive( true );
81  
82          List<String> result = scanner.scan( archetypeResources );
83  
84          assertEquals( 2, result.size() );
85          assertTrue( result.contains( "src\\main\\java\\App.java" ) );
86          assertTrue( result.contains( "src\\main\\java\\inner\\package\\App2.java" ) );
87      }
88  }