Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ public boolean isSymbolicLink( File parent, String name )
{
if ( Java7Detector.isJava7() )
{
return NioFiles.isSymbolicLink( parent );
return NioFiles.isSymbolicLink( new File( parent, name ) );
}
File resolvedParent = new File( parent.getCanonicalPath() );
File toTest = new File( resolvedParent, name );
Expand Down
45 changes: 41 additions & 4 deletions src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,44 @@ public void testRegexWithSlashInsideCharacterClass()
assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths );
}

public void testIsSymbolicLink()
throws IOException
{
// TODO: Uncomment when PR #25 merged
// if ( !checkTestFilesSymlinks() )
// {
// return;
// }

final File directory = new File( "src/test/resources/symlinks/src" );
DirectoryScanner ds = new DirectoryScanner();
assertTrue( ds.isSymbolicLink( directory, "symR" ) );
assertTrue( ds.isSymbolicLink( directory, "symDir" ) );
assertFalse( ds.isSymbolicLink( directory, "fileR.txt" ) );
assertFalse( ds.isSymbolicLink( directory, "aRegularDir" ) );
}

public void testIsParentSymbolicLink()
throws IOException
{
// TODO: Uncomment when PR #25 merged
// if ( !checkTestFilesSymlinks() )
// {
// return;
// }

final File directory = new File( "src/test/resources/symlinks/src" );
DirectoryScanner ds = new DirectoryScanner();
assertFalse( ds.isParentSymbolicLink( directory, "symR" ) );
assertFalse( ds.isParentSymbolicLink( directory, "symDir" ) );
assertFalse( ds.isParentSymbolicLink( directory, "fileR.txt" ) );
assertFalse( ds.isParentSymbolicLink( directory, "aRegularDir" ) );
assertFalse( ds.isParentSymbolicLink( new File( directory, "aRegularDir" ), "aRegulatFile.txt" ) );
assertTrue( ds.isParentSymbolicLink( new File( directory, "symDir" ), "targetFile.txt" ) );
assertTrue( ds.isParentSymbolicLink( new File( directory, "symLinkToDirOnTheOutside" ),
"FileInDirOnTheOutside.txt" ) );
}

private void printTestHeader()
{
StackTraceElement ste = new Throwable().getStackTrace()[1];
Expand Down Expand Up @@ -446,8 +484,7 @@ private void assertInclusionsAndExclusions( String[] files, String[] excludedPat
StringBuilder buffer = new StringBuilder();
if ( !failedToExclude.isEmpty() )
{
buffer.append( "Should NOT have included:\n" ).append(
StringUtils.join( failedToExclude.iterator(),
buffer.append( "Should NOT have included:\n" ).append( StringUtils.join( failedToExclude.iterator(),
"\n\t- " ) );
}

Expand All @@ -458,8 +495,8 @@ private void assertInclusionsAndExclusions( String[] files, String[] excludedPat
buffer.append( "\n\n" );
}

buffer.append( "Should have included:\n" )
.append( StringUtils.join( failedToInclude.iterator(), "\n\t- " ) );
buffer.append( "Should have included:\n" ).append( StringUtils.join( failedToInclude.iterator(),
"\n\t- " ) );
}

if ( buffer.length() > 0 )
Expand Down