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