Skip to content

Commit 8d807d3

Browse files
committed
Downgraded to java 1.8
1 parent 4b98287 commit 8d807d3

10 files changed

Lines changed: 89 additions & 125 deletions

File tree

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/discord.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ online {
99
autoUpdate = true
1010
updateDelay = 3600
1111
presets = [
12-
"https://raw.githubusercontent.com/intisy/gradle-snippets/presets/default.preset:17",
12+
"https://raw.githubusercontent.com/intisy/gradle-snippets/presets/default.preset:1.8",
1313
"https://raw.githubusercontent.com/intisy/gradle-snippets/presets/publish.preset"
1414
]
1515
}
@@ -20,8 +20,8 @@ repositories {
2020
}
2121

2222
java {
23-
sourceCompatibility = JavaVersion.VERSION_17
24-
targetCompatibility = JavaVersion.VERSION_17
23+
sourceCompatibility = JavaVersion.VERSION_1_8
24+
targetCompatibility = JavaVersion.VERSION_1_8
2525
}
2626

2727
dependencies {

src/main/java/io/github/intisy/docker/LinuxDockerProvider.java

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
import java.io.File;
1414
import java.io.IOException;
1515
import java.io.InputStream;
16-
import java.net.URI;
17-
import java.net.http.HttpClient;
18-
import java.net.http.HttpRequest;
19-
import java.net.http.HttpResponse;
16+
import java.net.HttpURLConnection;
17+
import java.net.URL;
2018
import java.nio.file.Files;
2119
import java.nio.file.Path;
20+
import java.nio.file.Paths;
2221
import java.nio.file.StandardCopyOption;
2322
import java.util.concurrent.TimeUnit;
2423

@@ -31,7 +30,7 @@ public class LinuxDockerProvider implements DockerProvider {
3130
private static final String ROOTLESSKIT_DOWNLOAD_URL = "https://github.com/rootless-containers/rootlesskit/releases/download/%s/rootlesskit-%s.tar.gz";
3231
private static final String DOCKER_ROOTLESS_SCRIPT_URL = "https://raw.githubusercontent.com/moby/moby/master/contrib/dockerd-rootless.sh";
3332
private static final String DOCKER_DOWNLOAD_URL = "https://download.docker.com/linux/static/stable/%s/docker-%s.tgz";
34-
private static final Path DOCKER_DIR = Path.of(System.getProperty("user.home"), ".docker-java");
33+
private static final Path DOCKER_DIR = Paths.get(System.getProperty("user.home"), ".docker-java");
3534
private static final Path DOCKER_PATH = DOCKER_DIR.resolve("docker/dockerd");
3635
private static final Path ROOTLESSKIT_PATH = DOCKER_DIR.resolve("rootlesskit");
3736
private static final Path DOCKER_SOCKET_PATH = DOCKER_DIR.resolve("run/docker.sock");
@@ -46,22 +45,22 @@ public class LinuxDockerProvider implements DockerProvider {
4645
private Process dockerProcess;
4746

4847
@Override
49-
public void ensureInstalled() throws IOException, InterruptedException {
48+
public void ensureInstalled() throws IOException {
5049
ensureDockerInstalled();
5150
ensureRootlessScriptInstalled();
5251
ensureRootlessKitInstalled();
5352
ensureSlirp4netnsInstalled();
5453
}
5554

5655
@SuppressWarnings("ResultOfMethodCallIgnored")
57-
private void ensureDockerInstalled() throws IOException, InterruptedException {
56+
private void ensureDockerInstalled() throws IOException {
5857
boolean autoUpdate = Boolean.parseBoolean(System.getProperty("docker.auto.update", "true"));
5958
String latestVersion = DockerVersionFetcher.getLatestVersion();
6059
boolean needsUpdate = true;
6160

6261
if (Files.exists(DOCKER_PATH)) {
6362
if (autoUpdate && Files.exists(DOCKER_VERSION_FILE)) {
64-
String installedVersion = Files.readString(DOCKER_VERSION_FILE).trim();
63+
String installedVersion = new String(Files.readAllBytes(DOCKER_VERSION_FILE)).trim();
6564
if (!installedVersion.equals(latestVersion)) {
6665
System.out.println("Newer Docker version available. Updating from " + installedVersion + " to " + latestVersion);
6766
} else {
@@ -88,20 +87,23 @@ private void ensureDockerInstalled() throws IOException, InterruptedException {
8887
String arch = getArch();
8988
String dockerUrl = String.format(DOCKER_DOWNLOAD_URL, arch, latestVersion);
9089
downloadAndExtract(dockerUrl, DOCKER_DIR);
91-
Files.writeString(DOCKER_VERSION_FILE, latestVersion);
90+
Files.write(DOCKER_VERSION_FILE, latestVersion.getBytes());
9291
}
9392
}
9493

9594
private String getArch() {
9695
String osArch = System.getProperty("os.arch");
97-
return switch (osArch) {
98-
case "amd64" -> "x86_64";
99-
case "aarch64" -> "aarch64";
100-
default -> throw new UnsupportedOperationException("Unsupported architecture: " + osArch);
101-
};
96+
switch (osArch) {
97+
case "amd64":
98+
return "x86_64";
99+
case "aarch64":
100+
return "aarch64";
101+
default:
102+
throw new UnsupportedOperationException("Unsupported architecture: " + osArch);
103+
}
102104
}
103105

104-
private void ensureRootlessScriptInstalled() throws IOException, InterruptedException {
106+
private void ensureRootlessScriptInstalled() throws IOException {
105107
Path rootlessScriptPath = DOCKER_PATH.getParent().resolve("dockerd-rootless.sh");
106108
if (!Files.exists(rootlessScriptPath)) {
107109
System.out.println("Downloading dockerd-rootless.sh script...");
@@ -110,7 +112,7 @@ private void ensureRootlessScriptInstalled() throws IOException, InterruptedExce
110112
}
111113
}
112114

113-
private void ensureRootlessKitInstalled() throws IOException, InterruptedException {
115+
private void ensureRootlessKitInstalled() throws IOException {
114116
if (Files.exists(ROOTLESSKIT_PATH.resolve("rootlesskit"))) {
115117
return;
116118
}
@@ -120,7 +122,7 @@ private void ensureRootlessKitInstalled() throws IOException, InterruptedExcepti
120122
System.out.println("RootlessKit installed successfully.");
121123
}
122124

123-
private void ensureSlirp4netnsInstalled() throws IOException, InterruptedException {
125+
private void ensureSlirp4netnsInstalled() throws IOException {
124126
if (Files.exists(SLIRP4NETNS_PATH)) {
125127
return;
126128
}
@@ -142,7 +144,6 @@ public void start() throws IOException, InterruptedException {
142144
if (isRoot() && !forceRootless) {
143145
System.out.println("Running as root, starting dockerd with sudo.");
144146
pb = new ProcessBuilder("sudo", DOCKER_PATH.toString(), "-H", "unix://" + DOCKER_SOCKET_PATH);
145-
dockerProcess = pb.start();
146147
} else {
147148
System.out.println("Attempting to start in rootless mode using dockerd-rootless.sh.");
148149

@@ -163,8 +164,8 @@ public void start() throws IOException, InterruptedException {
163164

164165
pb.redirectErrorStream(true);
165166
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
166-
dockerProcess = pb.start();
167167
}
168+
dockerProcess = pb.start();
168169

169170
if (!waitForSocket()) {
170171
throw new RuntimeException("Docker daemon failed to create socket in time.");
@@ -205,39 +206,37 @@ private boolean isRoot() {
205206
return username != null && username.equals("root");
206207
}
207208

208-
private void downloadFile(String urlString, Path destinationPath) throws IOException, InterruptedException {
209+
private void downloadFile(String urlString, Path destinationPath) throws IOException {
209210
System.out.println("Downloading " + urlString + " to " + destinationPath);
210-
HttpClient client = HttpClient.newBuilder()
211-
.followRedirects(HttpClient.Redirect.ALWAYS)
212-
.build();
213-
HttpRequest request = HttpRequest.newBuilder()
214-
.uri(URI.create(urlString))
215-
.build();
216-
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
217-
218-
if (response.statusCode() >= 400) {
219-
throw new IOException("Failed to download file: " + response.statusCode());
211+
URL url = new URL(urlString);
212+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
213+
connection.setInstanceFollowRedirects(true);
214+
connection.setRequestMethod("GET");
215+
connection.connect();
216+
217+
int responseCode = connection.getResponseCode();
218+
if (responseCode >= 400) {
219+
throw new IOException("Failed to download file: " + responseCode);
220220
}
221221

222-
try (InputStream in = response.body()) {
222+
try (InputStream in = connection.getInputStream()) {
223223
Files.copy(in, destinationPath, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
224224
}
225225
}
226226

227227
@SuppressWarnings("deprecation")
228-
private void downloadAndExtract(String urlString, Path destinationDir) throws IOException, InterruptedException {
228+
private void downloadAndExtract(String urlString, Path destinationDir) throws IOException {
229229
System.out.println("Downloading and extracting " + urlString + "...");
230-
HttpClient client = HttpClient.newBuilder()
231-
.followRedirects(HttpClient.Redirect.NORMAL)
232-
.build();
233-
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(urlString)).build();
234-
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
235-
236-
if (response.statusCode() != 200) {
237-
throw new IOException("Failed to download file from " + urlString + ". Status code: " + response.statusCode());
230+
URL url = new URL(urlString);
231+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
232+
connection.setInstanceFollowRedirects(true);
233+
connection.setRequestMethod("GET");
234+
235+
if (connection.getResponseCode() != 200) {
236+
throw new IOException("Failed to download file from " + urlString + ". Status code: " + connection.getResponseCode());
238237
}
239238

240-
try (InputStream is = response.body();
239+
try (InputStream is = connection.getInputStream();
241240
GzipCompressorInputStream gzis = new GzipCompressorInputStream(is);
242241
TarArchiveInputStream tis = new TarArchiveInputStream(gzis)) {
243242
TarArchiveEntry entry;

src/main/java/io/github/intisy/docker/MacDockerProvider.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
import java.io.File;
1313
import java.io.IOException;
1414
import java.io.InputStream;
15-
import java.net.URI;
16-
import java.net.http.HttpClient;
17-
import java.net.http.HttpRequest;
18-
import java.net.http.HttpResponse;
15+
import java.net.HttpURLConnection;
16+
import java.net.URL;
1917
import java.nio.file.Files;
2018
import java.nio.file.Path;
19+
import java.nio.file.Paths;
2120
import java.nio.file.StandardCopyOption;
2221
import java.util.concurrent.TimeUnit;
2322

@@ -27,7 +26,7 @@
2726
@SuppressWarnings({"ResultOfMethodCallIgnored", "BusyWait"})
2827
public class MacDockerProvider implements DockerProvider {
2928
private static final String DOCKER_DOWNLOAD_URL = "https://download.docker.com/mac/static/stable/%s/docker-%s.tgz";
30-
private static final Path DOCKER_DIR = Path.of(System.getProperty("user.home"), ".docker-java");
29+
private static final Path DOCKER_DIR = Paths.get(System.getProperty("user.home"), ".docker-java");
3130
private static final Path DOCKER_PATH = DOCKER_DIR.resolve("docker/dockerd");
3231
private static final Path DOCKER_SOCKET_PATH = DOCKER_DIR.resolve("run/docker.sock");
3332
private static final Path DOCKER_VERSION_FILE = DOCKER_DIR.resolve(".docker-version");
@@ -36,14 +35,14 @@ public class MacDockerProvider implements DockerProvider {
3635
private Process dockerProcess;
3736

3837
@Override
39-
public void ensureInstalled() throws IOException, InterruptedException {
38+
public void ensureInstalled() throws IOException {
4039
boolean autoUpdate = Boolean.parseBoolean(System.getProperty("docker.auto.update", "true"));
4140
String latestVersion = DockerVersionFetcher.getLatestVersion();
4241
boolean needsUpdate = true;
4342

4443
if (Files.exists(DOCKER_PATH)) {
4544
if (autoUpdate && Files.exists(DOCKER_VERSION_FILE)) {
46-
String installedVersion = Files.readString(DOCKER_VERSION_FILE).trim();
45+
String installedVersion = new String(Files.readAllBytes(DOCKER_VERSION_FILE)).trim();
4746
if (!installedVersion.equals(latestVersion)) {
4847
System.out.println("Newer Docker version available. Updating from " + installedVersion + " to " + latestVersion);
4948
} else {
@@ -70,17 +69,20 @@ public void ensureInstalled() throws IOException, InterruptedException {
7069
String arch = getArch();
7170
String dockerUrl = String.format(DOCKER_DOWNLOAD_URL, arch, latestVersion);
7271
downloadAndExtract(dockerUrl);
73-
Files.writeString(DOCKER_VERSION_FILE, latestVersion);
72+
Files.write(DOCKER_VERSION_FILE, latestVersion.getBytes());
7473
}
7574
}
7675

7776
private String getArch() {
7877
String osArch = System.getProperty("os.arch");
79-
return switch (osArch) {
80-
case "amd64" -> "x86_64";
81-
case "aarch64" -> "aarch64";
82-
default -> throw new UnsupportedOperationException("Unsupported architecture: " + osArch);
83-
};
78+
switch (osArch) {
79+
case "amd64":
80+
return "x86_64";
81+
case "aarch64":
82+
return "aarch64";
83+
default:
84+
throw new UnsupportedOperationException("Unsupported architecture: " + osArch);
85+
}
8486
}
8587

8688
@Override
@@ -131,19 +133,18 @@ public void stop() {
131133
}
132134

133135
@SuppressWarnings("deprecation")
134-
private void downloadAndExtract(String urlString) throws IOException, InterruptedException {
136+
private void downloadAndExtract(String urlString) throws IOException {
135137
System.out.println("Downloading and extracting " + urlString + "...");
136-
HttpClient client = HttpClient.newBuilder()
137-
.followRedirects(HttpClient.Redirect.NORMAL)
138-
.build();
139-
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(urlString)).build();
140-
HttpResponse<InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
141-
142-
if (response.statusCode() != 200) {
143-
throw new IOException("Failed to download file from " + urlString + ". Status code: " + response.statusCode());
138+
URL url = new URL(urlString);
139+
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
140+
connection.setInstanceFollowRedirects(true);
141+
connection.setRequestMethod("GET");
142+
143+
if (connection.getResponseCode() != 200) {
144+
throw new IOException("Failed to download file from " + urlString + ". Status code: " + connection.getResponseCode());
144145
}
145146

146-
try (InputStream is = response.body();
147+
try (InputStream is = connection.getInputStream();
147148
GzipCompressorInputStream gzis = new GzipCompressorInputStream(is);
148149
TarArchiveInputStream tis = new TarArchiveInputStream(gzis)) {
149150
TarArchiveEntry entry;

0 commit comments

Comments
 (0)