Skip to content

Commit ef9a78f

Browse files
axel3rdmichael-o
authored andcommitted
Fix DirectoryScanner.isSymbolicLink bug under Java 7
This fixes #28 and closes #29.
1 parent a9bc91d commit ef9a78f

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/main/java/org/codehaus/plexus/util/DirectoryScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ public boolean isSymbolicLink( File parent, String name )
729729
{
730730
if ( Java7Detector.isJava7() )
731731
{
732-
return NioFiles.isSymbolicLink( parent );
732+
return NioFiles.isSymbolicLink( new File( parent, name ) );
733733
}
734734
File resolvedParent = new File( parent.getCanonicalPath() );
735735
File toTest = new File( resolvedParent, name );

src/test/java/org/codehaus/plexus/util/DirectoryScannerTest.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,44 @@ public void testRegexWithSlashInsideCharacterClass()
405405
assertInclusionsAndExclusions( ds.getIncludedFiles(), excludedPaths, includedPaths );
406406
}
407407

408+
public void testIsSymbolicLink()
409+
throws IOException
410+
{
411+
// TODO: Uncomment when PR #25 merged
412+
// if ( !checkTestFilesSymlinks() )
413+
// {
414+
// return;
415+
// }
416+
417+
final File directory = new File( "src/test/resources/symlinks/src" );
418+
DirectoryScanner ds = new DirectoryScanner();
419+
assertTrue( ds.isSymbolicLink( directory, "symR" ) );
420+
assertTrue( ds.isSymbolicLink( directory, "symDir" ) );
421+
assertFalse( ds.isSymbolicLink( directory, "fileR.txt" ) );
422+
assertFalse( ds.isSymbolicLink( directory, "aRegularDir" ) );
423+
}
424+
425+
public void testIsParentSymbolicLink()
426+
throws IOException
427+
{
428+
// TODO: Uncomment when PR #25 merged
429+
// if ( !checkTestFilesSymlinks() )
430+
// {
431+
// return;
432+
// }
433+
434+
final File directory = new File( "src/test/resources/symlinks/src" );
435+
DirectoryScanner ds = new DirectoryScanner();
436+
assertFalse( ds.isParentSymbolicLink( directory, "symR" ) );
437+
assertFalse( ds.isParentSymbolicLink( directory, "symDir" ) );
438+
assertFalse( ds.isParentSymbolicLink( directory, "fileR.txt" ) );
439+
assertFalse( ds.isParentSymbolicLink( directory, "aRegularDir" ) );
440+
assertFalse( ds.isParentSymbolicLink( new File( directory, "aRegularDir" ), "aRegulatFile.txt" ) );
441+
assertTrue( ds.isParentSymbolicLink( new File( directory, "symDir" ), "targetFile.txt" ) );
442+
assertTrue( ds.isParentSymbolicLink( new File( directory, "symLinkToDirOnTheOutside" ),
443+
"FileInDirOnTheOutside.txt" ) );
444+
}
445+
408446
private void printTestHeader()
409447
{
410448
StackTraceElement ste = new Throwable().getStackTrace()[1];
@@ -446,8 +484,7 @@ private void assertInclusionsAndExclusions( String[] files, String[] excludedPat
446484
StringBuilder buffer = new StringBuilder();
447485
if ( !failedToExclude.isEmpty() )
448486
{
449-
buffer.append( "Should NOT have included:\n" ).append(
450-
StringUtils.join( failedToExclude.iterator(),
487+
buffer.append( "Should NOT have included:\n" ).append( StringUtils.join( failedToExclude.iterator(),
451488
"\n\t- " ) );
452489
}
453490

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

461-
buffer.append( "Should have included:\n" )
462-
.append( StringUtils.join( failedToInclude.iterator(), "\n\t- " ) );
498+
buffer.append( "Should have included:\n" ).append( StringUtils.join( failedToInclude.iterator(),
499+
"\n\t- " ) );
463500
}
464501

465502
if ( buffer.length() > 0 )

0 commit comments

Comments
 (0)