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.scm;
20  
21  import java.io.File;
22  import java.io.IOException;
23  import java.util.Iterator;
24  import java.util.List;
25  
26  import org.junit.Test;
27  
28  import static org.junit.Assert.assertEquals;
29  import static org.junit.Assert.assertTrue;
30  import static org.junit.Assert.fail;
31  
32  /**
33   * @author dtran
34   */
35  public class ScmFileSetTest {
36      private static String basedirPath;
37  
38      public static String getBasedir() {
39          if (basedirPath != null) {
40              return basedirPath;
41          }
42  
43          basedirPath = System.getProperty("basedir");
44  
45          if (basedirPath == null) {
46              basedirPath = new File("").getAbsolutePath();
47          }
48  
49          return basedirPath;
50      }
51  
52      private String removeBasedir(String filename) {
53          return filename.substring(getBasedir().length(), filename.length());
54      }
55  
56      @Test
57      public void testFilesList() throws IOException {
58          ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**");
59          assertEquals("src", fileSet.getBasedir().getName());
60          assertEquals("**/**", fileSet.getIncludes());
61          // assertEquals( ScmFileSet.DEFAULT_EXCLUDES, fileSet.getExcludes() );
62          assertTrue(
63                  "List of files should be longer than 10 elements, but received: "
64                          + fileSet.getFileList().size(),
65                  fileSet.getFileList().size() > 10);
66      }
67  
68      @Test
69      public void testFilesListWithoutIncludesResultsEmptyList() throws IOException {
70          ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"));
71          assertEquals(0, fileSet.getFileList().size());
72      }
73  
74      @Test
75      public void testFilesListExcludes() throws IOException {
76          ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**", "**/exclude/**");
77  
78          List<File> files = fileSet.getFileList();
79  
80          Iterator<File> it = files.iterator();
81          while (it.hasNext()) {
82              File file = (File) it.next();
83              if (removeBasedir(file.getAbsolutePath()).indexOf("exclude") != -1) {
84                  fail("Found excludes in file set: " + file);
85              }
86          }
87      }
88  
89      @Test
90      public void testFilesListExcludes2() throws IOException {
91          ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**", "**/exclude/**");
92  
93          assertEquals(2, fileSet.getFileList().size());
94      }
95  
96      @Test
97      public void testFilesListNoExcludes() throws IOException {
98          ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**");
99  
100         assertEquals(4, fileSet.getFileList().size());
101     }
102 }