public Transporter newInstance()

in maven-resolver-transport-file/src/main/java/org/eclipse/aether/transport/file/FileTransporterFactory.java [75:124]


    public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
            throws NoTransporterException {
        requireNonNull(session, "session cannot be null");
        requireNonNull(repository, "repository cannot be null");

        String repositoryUrl = repository.getUrl();
        if (repositoryUrl.startsWith("bundle:")) {
            try {
                repositoryUrl = repositoryUrl.substring("bundle:".length());
                URI bundlePath = URI.create("jar:"
                        + Paths.get(RepositoryUriUtils.toUri(repositoryUrl))
                                .toAbsolutePath()
                                .toUri()
                                .toASCIIString());
                Map<String, String> env = new HashMap<>();
                FileSystem fileSystem = FileSystems.newFileSystem(bundlePath, env);
                return new FileTransporter(
                        fileSystem,
                        true,
                        false,
                        fileSystem.getPath(fileSystem.getSeparator()),
                        FileTransporter.WriteOp.COPY);
            } catch (IOException e) {
                throw new UncheckedIOException(e); // hard failure; most probably user error (ie wrong path or perm)
            }
        } else {
            // special case in file: transport: to support custom FS providers (like JIMFS), we cannot
            // cover all possible protocols (to throw NoTransporterEx), hence we rely on FS rejecting the URI
            FileTransporter.WriteOp writeOp = FileTransporter.WriteOp.COPY;
            if (repositoryUrl.startsWith("symlink+")) {
                writeOp = FileTransporter.WriteOp.SYMLINK;
                repositoryUrl = repositoryUrl.substring("symlink+".length());
            } else if (repositoryUrl.startsWith("hardlink+")) {
                writeOp = FileTransporter.WriteOp.HARDLINK;
                repositoryUrl = repositoryUrl.substring("hardlink+".length());
            }
            try {
                Path basePath =
                        Paths.get(RepositoryUriUtils.toUri(repositoryUrl)).toAbsolutePath();
                return new FileTransporter(
                        basePath.getFileSystem(),
                        false,
                        !basePath.getFileSystem().isReadOnly(),
                        basePath,
                        writeOp);
            } catch (FileSystemNotFoundException | IllegalArgumentException e) {
                throw new NoTransporterException(repository, e);
            }
        }
    }