All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.gradle.plugins.utils.JavaNIOUtils.groovy Maven / Gradle / Ivy

package com.netflix.gradle.plugins.utils

import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path

final class JavaNIOUtils {
    private JavaNIOUtils() {}

    static Path createPath(String filePath) {
        FileSystems.getDefault().getPath(filePath)
    }

    static boolean isSymbolicLink(File file) {
        Path path = createPath(file.path)
        Files.isSymbolicLink(path)
    }

    static File parentSymbolicLink(File file) {
        File currentParent = file.parentFile
        if (currentParent == null || isSymbolicLink(currentParent)) return currentParent else return parentSymbolicLink(currentParent)
    }

    static Path readSymbolicLink(Path path) {
        Files.readSymbolicLink(path)
    }

    static void createSymbolicLink(File source, File target) {
        Path newLink = createPath(source.path)
        Path targetDir = createPath(target.path)
        Files.createSymbolicLink(newLink, targetDir)
    }

    static Path createTempFile(String prefix, String suffix) {
        return Files.createTempFile(prefix, suffix)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy