diff --git a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java index 16377510..9d3500ee 100644 --- a/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java +++ b/src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java @@ -20,17 +20,22 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TestName; /** * Base class for testcases doing tests with files. @@ -40,6 +45,9 @@ public class DirectoryScannerTest extends FileBasedTestCase { + @Rule + public TestName name = new TestName(); + private static String testDir = getTestDirectory().getPath(); @Test @@ -118,6 +126,47 @@ private void createTestFiles() this.createFile( new File( testDir + "/scanner4.dat" ), 0 ); this.createFile( new File( testDir + "/scanner5.dat" ), 0 ); } + + /** + * Check if 'src/test/resources/symlinks/src/sym*' test files (start with 'sym') exist and are symlinks.
+ * On some OS (like Windows 10), the 'git clone' requires to be executed with admin permissions and the + * 'core.symlinks=true' git option. + * + * @return true If files here and symlinks, false otherwise + */ + private boolean checkTestFilesSymlinks() + { + File symlinksDirectory = new File( "src/test/resources/symlinks/src" ); + try + { + List symlinks = + FileUtils.getFileAndDirectoryNames( symlinksDirectory, "sym*", null, true, true, true, true ); + if ( symlinks.isEmpty() ) + { + throw new IOException( "Symlinks files/directories are not present" ); + } + for ( String symLink : symlinks ) + { + if ( !Files.isSymbolicLink( Paths.get( symLink ) ) ) + { + throw new IOException( String.format( "Path is not a symlink: %s", symLink ) ); + } + } + return true; + } + catch ( IOException e ) + { + System.err.println( String.format( "The unit test '%s.%s' will be skipped, reason: %s", + this.getClass().getSimpleName(), name.getMethodName(), + e.getMessage() ) ); + System.out.println( String.format( "This test requires symlinks files in '%s' directory.", + symlinksDirectory.getPath() ) ); + System.out.println( "On some OS (like Windows 10), files are present only if the clone/checkout is done" + + " in administrator mode, and correct (symlinks and not flat file/directory)" + + " if symlinks option are used (for git: git clone -c core.symlinks=true [url])" ); + return false; + } + } @Test public void testGeneral() @@ -158,6 +207,8 @@ public void testIncludesExcludesWithWhiteSpaces() @Test public void testFollowSymlinksFalse() { + assumeTrue( checkTestFilesSymlinks() ); + DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir( new File( "src/test/resources/symlinks/src/" ) ); ds.setFollowSymlinks( false ); @@ -190,6 +241,8 @@ private void assertAlwaysIncluded( List included ) @Test public void testFollowSymlinks() { + assumeTrue( checkTestFilesSymlinks() ); + DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir( new File( "src/test/resources/symlinks/src/" ) ); ds.setFollowSymlinks( true ); @@ -428,11 +481,7 @@ public void testRegexWithSlashInsideCharacterClass() public void testIsSymbolicLink() throws IOException { - // TODO: Uncomment when PR #25 merged - // if ( !checkTestFilesSymlinks() ) - // { - // return; - // } + assumeTrue( checkTestFilesSymlinks() ); final File directory = new File( "src/test/resources/symlinks/src" ); DirectoryScanner ds = new DirectoryScanner(); @@ -446,11 +495,7 @@ public void testIsSymbolicLink() public void testIsParentSymbolicLink() throws IOException { - // TODO: Uncomment when PR #25 merged - // if ( !checkTestFilesSymlinks() ) - // { - // return; - // } + assumeTrue( checkTestFilesSymlinks() ); final File directory = new File( "src/test/resources/symlinks/src" ); DirectoryScanner ds = new DirectoryScanner();