Search in sources :

Example 6 with LinkOption

use of java.nio.file.LinkOption in project buck by facebook.

the class DefaultJavaLibraryTest method testJavaLibaryThrowsIfResourceIsDirectory.

@Test
public void testJavaLibaryThrowsIfResourceIsDirectory() throws Exception {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem() {

        @Override
        public boolean isDirectory(Path path, LinkOption... linkOptionsk) {
            return true;
        }
    };
    try {
        JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//library:code")).addResource(new FakeSourcePath("library")).build(ruleResolver, filesystem);
        fail("An exception should have been thrown because a directory was passed as a resource.");
    } catch (HumanReadableException e) {
        assertTrue(e.getHumanReadableErrorMessage().contains("a directory is not a valid input"));
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) LinkOption(java.nio.file.LinkOption) HumanReadableException(com.facebook.buck.util.HumanReadableException) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 7 with LinkOption

use of java.nio.file.LinkOption in project jdk8u_jdk by JetBrains.

the class CopyAndMove method copyAndVerify.

// copy source to target with verification
static void copyAndVerify(Path source, Path target, CopyOption... options) throws IOException {
    Path result = copy(source, target, options);
    assertTrue(result == target);
    // get attributes of source and target file to verify copy
    boolean followLinks = true;
    LinkOption[] linkOptions = new LinkOption[0];
    boolean copyAttributes = false;
    for (CopyOption opt : options) {
        if (opt == NOFOLLOW_LINKS) {
            followLinks = false;
            linkOptions = new LinkOption[] { NOFOLLOW_LINKS };
        }
        if (opt == COPY_ATTRIBUTES)
            copyAttributes = true;
    }
    BasicFileAttributes basicAttributes = readAttributes(source, BasicFileAttributes.class, linkOptions);
    // check hash if regular file
    if (basicAttributes.isRegularFile())
        assertTrue(computeHash(source) == computeHash(target));
    // check link target if symbolic link
    if (basicAttributes.isSymbolicLink())
        assert (readSymbolicLink(source).equals(readSymbolicLink(target)));
    // check that attributes are copied
    if (copyAttributes && followLinks) {
        checkBasicAttributes(basicAttributes, readAttributes(source, BasicFileAttributes.class, linkOptions));
        // verify other attributes when same provider
        if (source.getFileSystem().provider() == target.getFileSystem().provider()) {
            // check POSIX attributes are copied
            String os = System.getProperty("os.name");
            if ((os.equals("SunOS") || os.equals("Linux")) && testPosixAttributes) {
                checkPosixAttributes(readAttributes(source, PosixFileAttributes.class, linkOptions), readAttributes(target, PosixFileAttributes.class, linkOptions));
            }
            // check DOS attributes are copied
            if (os.startsWith("Windows")) {
                checkDosAttributes(readAttributes(source, DosFileAttributes.class, linkOptions), readAttributes(target, DosFileAttributes.class, linkOptions));
            }
            // check named attributes are copied
            if (followLinks && getFileStore(source).supportsFileAttributeView("xattr") && getFileStore(target).supportsFileAttributeView("xattr")) {
                checkUserDefinedFileAttributes(readUserDefinedFileAttributes(source), readUserDefinedFileAttributes(target));
            }
        }
    }
}
Also used : StandardCopyOption(java.nio.file.StandardCopyOption) LinkOption(java.nio.file.LinkOption)

Example 8 with LinkOption

use of java.nio.file.LinkOption in project cryptofs by cryptomator.

the class CryptoFileSystemProviderTest method testReadAttributesWithNameDelegatesToFileSystem.

@Test
public void testReadAttributesWithNameDelegatesToFileSystem() throws IOException {
    @SuppressWarnings("unchecked") Map<String, Object> attributes = mock(Map.class);
    LinkOption option = LinkOption.NOFOLLOW_LINKS;
    String name = "foobar";
    when(cryptoFileSystem.readAttributes(cryptoPath, name, option)).thenReturn(attributes);
    Map<String, Object> result = inTest.readAttributes(cryptoPath, name, option);
    assertThat(result, is(attributes));
}
Also used : LinkOption(java.nio.file.LinkOption) Test(org.junit.Test)

Example 9 with LinkOption

use of java.nio.file.LinkOption in project cryptofs by cryptomator.

the class CryptoFileSystemProviderTest method testGetFileAttributeViewDelegatesToFileSystem.

@Test
public void testGetFileAttributeViewDelegatesToFileSystem() {
    FileAttributeView view = mock(FileAttributeView.class);
    LinkOption option = LinkOption.NOFOLLOW_LINKS;
    when(cryptoFileSystem.getFileAttributeView(cryptoPath, FileAttributeView.class, option)).thenReturn(view);
    FileAttributeView result = inTest.getFileAttributeView(cryptoPath, FileAttributeView.class, option);
    assertThat(result, is(view));
}
Also used : LinkOption(java.nio.file.LinkOption) FileAttributeView(java.nio.file.attribute.FileAttributeView) Test(org.junit.Test)

Example 10 with LinkOption

use of java.nio.file.LinkOption in project cryptofs by cryptomator.

the class CryptoFileSystemProviderTest method testReadAttributesWithTypeDelegatesToFileSystem.

@Test
public void testReadAttributesWithTypeDelegatesToFileSystem() throws IOException {
    BasicFileAttributes attributes = mock(BasicFileAttributes.class);
    LinkOption option = LinkOption.NOFOLLOW_LINKS;
    when(cryptoFileSystem.readAttributes(cryptoPath, BasicFileAttributes.class, option)).thenReturn(attributes);
    BasicFileAttributes result = inTest.readAttributes(cryptoPath, BasicFileAttributes.class, option);
    assertThat(result, is(attributes));
}
Also used : LinkOption(java.nio.file.LinkOption) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Aggregations

LinkOption (java.nio.file.LinkOption)11 Test (org.junit.Test)6 Path (java.nio.file.Path)4 IOException (java.io.IOException)3 CopyOption (java.nio.file.CopyOption)3 StandardCopyOption (java.nio.file.StandardCopyOption)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)2 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)2 SeekableByteChannel (java.nio.channels.SeekableByteChannel)2 AccessMode (java.nio.file.AccessMode)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)2 FileAttributeView (java.nio.file.attribute.FileAttributeView)2