Skip to content

#28: Fix DirectoryScanner.isSymbolicLink bug under Java 7 #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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