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