Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unixsocket support from Java 16+ #290

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.28.0",
org.eclipse.equinox.security,
org.eclipse.osgi,
org.mandas.docker-client;bundle-version="4.0.3",
com.github.jnr.unixsocket;bundle-version="0.38.20",
com.github.jnr.enxio;bundle-version="0.32.15",
org.glassfish.jersey.core.jersey-client;bundle-version="2.40",
org.glassfish.jersey.media.jersey-media-json-jackson;bundle-version="2.40",
org.glassfish.jersey.core.jersey-common;bundle-version="2.40",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Red Hat.
*
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -14,27 +14,28 @@

import java.io.File;
import java.io.IOException;
import java.net.UnixDomainSocketAddress;
import java.nio.channels.SocketChannel;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
import org.eclipse.linuxtools.docker.core.IDockerConnectionSettingsProvider;

import jnr.unixsocket.UnixSocketAddress;
import jnr.unixsocket.UnixSocketChannel;

public class DefaultUnixConnectionSettingsProvider implements IDockerConnectionSettingsProvider {
public class DefaultUnixConnectionSettingsProvider
implements IDockerConnectionSettingsProvider {

@Override
public List<IDockerConnectionSettings> getConnectionSettings() {
final File unixSocketFile = new File("/var/run/docker.sock"); //$NON-NLS-1$
final Path unixSocketPath = Path.of("/var/run/docker.sock"); //$NON-NLS-1$
File unixSocketFile = unixSocketPath.toFile();
if (unixSocketFile.exists() && unixSocketFile.canRead()
&& unixSocketFile.canWrite()) {
final UnixSocketAddress address = new UnixSocketAddress(
unixSocketFile);
try (final UnixSocketChannel channel = UnixSocketChannel
.open(address)) {
final UnixDomainSocketAddress address = UnixDomainSocketAddress
.of(unixSocketPath);
try (final SocketChannel channel = SocketChannel.open(address)) {
// assume socket works
final UnixSocketConnectionSettings socket = new UnixSocketConnectionSettings(
DefaultDockerConnectionSettingsFinder.Defaults.DEFAULT_UNIX_SOCKET_PATH);
Expand Down