001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm; 020 021import java.io.File; 022import java.io.IOException; 023import java.util.Iterator; 024import java.util.List; 025 026import org.junit.Test; 027 028import static org.junit.Assert.assertEquals; 029import static org.junit.Assert.assertTrue; 030import static org.junit.Assert.fail; 031 032/** 033 * @author dtran 034 */ 035public class ScmFileSetTest { 036 private static String basedirPath; 037 038 public static String getBasedir() { 039 if (basedirPath != null) { 040 return basedirPath; 041 } 042 043 basedirPath = System.getProperty("basedir"); 044 045 if (basedirPath == null) { 046 basedirPath = new File("").getAbsolutePath(); 047 } 048 049 return basedirPath; 050 } 051 052 private String removeBasedir(String filename) { 053 return filename.substring(getBasedir().length(), filename.length()); 054 } 055 056 @Test 057 public void testFilesList() throws IOException { 058 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**"); 059 assertEquals("src", fileSet.getBasedir().getName()); 060 assertEquals("**/**", fileSet.getIncludes()); 061 // assertEquals( ScmFileSet.DEFAULT_EXCLUDES, fileSet.getExcludes() ); 062 assertTrue( 063 "List of files should be longer than 10 elements, but received: " 064 + fileSet.getFileList().size(), 065 fileSet.getFileList().size() > 10); 066 } 067 068 @Test 069 public void testFilesListWithoutIncludesResultsEmptyList() throws IOException { 070 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src")); 071 assertEquals(0, fileSet.getFileList().size()); 072 } 073 074 @Test 075 public void testFilesListExcludes() throws IOException { 076 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/**", "**/exclude/**"); 077 078 List<File> files = fileSet.getFileList(); 079 080 Iterator<File> it = files.iterator(); 081 while (it.hasNext()) { 082 File file = (File) it.next(); 083 if (removeBasedir(file.getAbsolutePath()).indexOf("exclude") != -1) { 084 fail("Found excludes in file set: " + file); 085 } 086 } 087 } 088 089 @Test 090 public void testFilesListExcludes2() throws IOException { 091 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**", "**/exclude/**"); 092 093 assertEquals(2, fileSet.getFileList().size()); 094 } 095 096 @Test 097 public void testFilesListNoExcludes() throws IOException { 098 ScmFileSet fileSet = new ScmFileSet(new File(getBasedir(), "src"), "**/scmfileset/**"); 099 100 assertEquals(4, fileSet.getFileList().size()); 101 } 102}