Skip to content

Commit

Permalink
Fail assumption when symlinks not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Aug 28, 2020
1 parent 2006d95 commit 60fc531
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
* under the License.
*/

import static org.junit.Assume.assumeTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.FileSystemException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -155,6 +158,27 @@ public void assertFileExists( ArtifactItem item, boolean exist )
assertEquals( exist, file.exists() );
}

private static final boolean supportsSymbolicLinks = supportsSymbolicLinks();

private static boolean supportsSymbolicLinks( )
{
try {
Path target = Files.createTempFile( null, null );
Path link = Files.createTempFile( null, null );
Files.delete( link );
try {
Files.createSymbolicLink( link, target );
} catch ( FileSystemException e ) {
return false;
}
Files.delete( link );
Files.delete( target );
return true;
} catch ( IOException e ) {
throw new RuntimeException( e );
}
}

public void assertFilesAreLinks( Collection<ArtifactItem> items, boolean areLinks )
{
for ( ArtifactItem item : items )
Expand Down Expand Up @@ -268,6 +292,8 @@ public void testCopyToLocation()
public void testLink()
throws Exception
{
assumeTrue("supports symbolic links", supportsSymbolicLinks);

List<ArtifactItem> list = stubFactory.getArtifactItems( stubFactory.getClassifiedArtifacts() );

mojo.setArtifactItems( createArtifactItemArtifacts( list ) );
Expand Down

0 comments on commit 60fc531

Please sign in to comment.