private void symlinkToPathDir()

in plugins/sandbox/src/main/java/co/elastic/gradle/sandbox/SandboxExecTask.java [150:173]


    private void symlinkToPathDir(final List<File> binaries) {
        List<File> directoryRuns = binaries.stream().filter(File::isDirectory).toList();
        if (!directoryRuns.isEmpty()) {
            throw new GradleException("Configured `runs` need to be files but these are directories instead: " + directoryRuns);
        }
        List<File> nonExistentRuns = binaries.stream().filter(each -> !each.exists()).toList();
        if (!nonExistentRuns.isEmpty()) {
            throw new GradleException("Configured `runs` don't exist: " + nonExistentRuns);
        }
        binaries.stream()
                .map(File::toPath)
                .forEach(runs -> {
                    try {
                        final Path link = pathDir.resolve(runs.getFileName());
                        if (Files.exists(link)) {
                            // We re-create te path dir with retries so the targets might exist
                            Files.delete(link);
                        }
                        Files.createSymbolicLink(link, runs);
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                });
    }