-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJdkDiscovery.java
More file actions
75 lines (63 loc) · 1.78 KB
/
JdkDiscovery.java
File metadata and controls
75 lines (63 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package dev.jbang.devkitman;
import static dev.jbang.devkitman.util.FileUtils.deleteOnExit;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
/**
* This interface gives JDK providers the ability to be discovered and
* instantiated by code that doesn't know about the specific API the provider
* implements. See {@link JdkProviders} for a possible implementation of the
* discovery mechanism.
*/
public interface JdkDiscovery {
@NonNull
String name();
@Nullable
JdkProvider create(@NonNull Config config);
class Config {
@NonNull
private final Path installPath;
private Path cachePath;
@NonNull
private final Map<String, String> properties;
public Config(@NonNull Path installPaths) {
this(installPaths, null, null);
}
public Config(
@NonNull Path installPath,
@Nullable Path cachePath,
@Nullable Map<String, String> properties) {
this.installPath = installPath;
this.cachePath = cachePath;
this.properties = new HashMap<>();
if (properties != null) {
this.properties.putAll(properties);
}
}
public @NonNull Path installPath() {
return installPath;
}
public @NonNull Path cachePath() {
if (cachePath == null) {
// If no cache path is set, we create a temp dir as a curtesy that will be
// deleted on exit
try {
cachePath = deleteOnExit(Files.createTempDirectory("jdk-provider-cache"));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return cachePath;
}
public @NonNull Map<String, String> properties() {
return properties;
}
public Config copy() {
return new Config(installPath, cachePath, properties);
}
}
}