Skip to content

Commit 32ba860

Browse files
committed
feat: implemented support for Jdk distro and tags
1 parent b0b4903 commit 32ba860

19 files changed

+698
-84
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dev.jbang.devkitman;
2+
3+
public class Distro {
4+
public final String name;
5+
public final boolean isGraalVM;
6+
7+
public Distro(String name, boolean isGraalVM) {
8+
this.name = name;
9+
this.isGraalVM = isGraalVM;
10+
}
11+
}

src/main/java/dev/jbang/devkitman/Jdk.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.jbang.devkitman;
22

33
import java.nio.file.Path;
4+
import java.util.Collections;
45
import java.util.HashSet;
56
import java.util.Objects;
67
import java.util.Set;
@@ -46,6 +47,11 @@ public interface Jdk extends Comparable<Jdk> {
4647
/**
4748
* Returns the major version of the JDK
4849
*/
50+
String distro();
51+
52+
@NonNull
53+
Set<String> tags();
54+
4955
int majorVersion();
5056

5157
/**
@@ -78,21 +84,25 @@ class Default implements Jdk {
7884
private final boolean fixedVersion;
7985
@Nullable
8086
private final Path home;
87+
private final String distro;
8188
@NonNull
82-
private final Set<String> tags = new HashSet<>();
89+
private final Set<String> tags;
8390

8491
Default(
8592
@NonNull JdkProvider provider,
8693
@NonNull String id,
8794
@Nullable Path home,
8895
@NonNull String version,
8996
boolean fixedVersion,
90-
@NonNull String... tags) {
97+
String distro,
98+
@NonNull Set<String> tags) {
9199
this.provider = provider;
92100
this.id = id;
93101
this.version = version;
94102
this.fixedVersion = fixedVersion;
95103
this.home = home;
104+
this.distro = distro;
105+
this.tags = Collections.unmodifiableSet(new HashSet<>(tags));
96106
}
97107

98108
@Override
@@ -128,6 +138,17 @@ public Path home() {
128138
return home;
129139
}
130140

141+
@Override
142+
public String distro() {
143+
return distro;
144+
}
145+
146+
@Override
147+
@NonNull
148+
public Set<String> tags() {
149+
return tags;
150+
}
151+
131152
@Override
132153
public int majorVersion() {
133154
return JavaUtils.parseJavaVersion(version());

src/main/java/dev/jbang/devkitman/JdkInstaller.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.nio.file.Path;
44
import java.util.List;
5+
import java.util.Set;
56

67
import org.jspecify.annotations.NonNull;
78
import org.jspecify.annotations.Nullable;
@@ -13,17 +14,33 @@
1314
*/
1415
public interface JdkInstaller {
1516

17+
/**
18+
* This method returns a list of distributions that are supported by this
19+
* installer.
20+
*
21+
* @return List of distribution names
22+
*/
23+
@NonNull
24+
default List<Distro> listDistros() {
25+
throw new UnsupportedOperationException(
26+
"Listing available distributions is not supported by " + getClass().getName());
27+
}
28+
1629
/**
1730
* This method returns a set of JDKs that are available for installation.
1831
* Implementations might set the <code>home</code> field of the JDK objects if
1932
* the respective JDK is currently installed on the user's system, but only if
2033
* they can ensure that it's the exact same version, otherwise they should just
2134
* leave the field <code>null</code>.
2235
*
36+
* @param distros Comma separated list of distribution names to look for. Can be
37+
* null to use a default selection defined by the installer. Use
38+
* an empty string to list all.
39+
* @param tags The tags to filter the JDKs by. Can be null to list all.
2340
* @return List of <code>Jdk</code> objects
2441
*/
2542
@NonNull
26-
default List<Jdk> listAvailable() {
43+
default List<Jdk> listAvailable(String distros, Set<String> tags) {
2744
throw new UnsupportedOperationException(
2845
"Listing available JDKs is not supported by " + getClass().getName());
2946
}
@@ -43,7 +60,7 @@ default List<Jdk> listAvailable() {
4360
*/
4461
@Nullable
4562
default Jdk getAvailableByIdOrToken(String idOrToken) {
46-
return JdkManager.getJdkBy(listAvailable().stream(), Jdk.Predicates.id(idOrToken))
63+
return JdkManager.getJdkBy(listAvailable(null, null).stream(), Jdk.Predicates.id(idOrToken))
4764
.orElse(null);
4865
}
4966

src/main/java/dev/jbang/devkitman/JdkManager.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,19 @@ private Optional<Jdk> prevAvailableJdk(int maxVersion) {
527527
.max(Jdk::compareTo);
528528
}
529529

530+
public Set<Distro> listAvailableDistros() {
531+
return providers(JdkProvider.Predicates.canUpdate)
532+
.flatMap(p -> p.listDistros().stream())
533+
.collect(Collectors.toSet());
534+
}
535+
530536
public List<Jdk> listAvailableJdks() {
537+
return listAvailableJdks(null, null);
538+
}
539+
540+
public List<Jdk> listAvailableJdks(String distros, Set<String> tags) {
531541
return providers(JdkProvider.Predicates.canUpdate)
532-
.flatMap(p -> p.listAvailable().stream())
542+
.flatMap(p -> p.listAvailable(distros, tags).stream())
533543
.collect(Collectors.toList());
534544
}
535545

@@ -563,7 +573,9 @@ public void setDefaultJdk(Jdk jdk) {
563573
DefaultJdkProvider.Discovery.PROVIDER_ID,
564574
jdk.home(),
565575
jdk.version(),
566-
false);
576+
false,
577+
jdk.distro(),
578+
jdk.tags());
567579
defaultProvider.install(newDefJdk);
568580
LOGGER.log(Level.INFO, "Default JDK set to {0}", jdk);
569581
}

src/main/java/dev/jbang/devkitman/JdkProvider.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@
2020
*/
2121
public interface JdkProvider {
2222

23-
default Jdk createJdk(@NonNull String id, @Nullable Path home, @NonNull String version, boolean fixedVersion) {
24-
return new Jdk.Default(this, id, home, version, fixedVersion);
23+
default Jdk createJdk(@NonNull String id,
24+
@Nullable Path home,
25+
@NonNull String version,
26+
boolean fixedVersion,
27+
String distro,
28+
@NonNull Set<String> tags) {
29+
return new Jdk.Default(this, id, home, version, fixedVersion, distro, tags);
2530
}
2631

2732
@NonNull
@@ -134,17 +139,34 @@ default boolean canUpdate() {
134139
return false;
135140
}
136141

142+
/**
143+
* This method returns a list of distributions that are available for
144+
* installation. The list can be empty if the provider does not support
145+
* selecting distributions.
146+
*
147+
* @return List of distribution names
148+
*/
149+
@NonNull
150+
default List<Distro> listDistros() {
151+
throw new UnsupportedOperationException(
152+
"Listing available distributions is not supported by " + getClass().getName());
153+
}
154+
137155
/**
138156
* This method returns a set of JDKs that are available for installation.
139157
* Implementations might set the <code>home</code> field of the JDK objects if
140158
* the respective JDK is currently installed on the user's system, but only if
141159
* they can ensure that it's the exact same version, otherwise they should just
142160
* leave the field <code>null</code>.
143161
*
162+
* @param distros Comma separated list of distribution names to look for. Can be
163+
* null to use a default selection defined by the installer. Use
164+
* an empty string to list all.
165+
* @param tags The tags to filter the JDKs by. Can be null to list all.
144166
* @return List of <code>Jdk</code> objects
145167
*/
146168
@NonNull
147-
default List<Jdk> listAvailable() {
169+
default List<Jdk> listAvailable(String distros, Set<String> tags) {
148170
throw new UnsupportedOperationException(
149171
"Listing available JDKs is not supported by " + getClass().getName());
150172
}
@@ -164,7 +186,7 @@ default List<Jdk> listAvailable() {
164186
*/
165187
@Nullable
166188
default Jdk getAvailableByIdOrToken(String idOrToken) {
167-
return JdkManager.getJdkBy(listAvailable().stream(), Jdk.Predicates.id(idOrToken))
189+
return JdkManager.getJdkBy(listAvailable(null, null).stream(), Jdk.Predicates.id(idOrToken))
168190
.orElse(null);
169191
}
170192

0 commit comments

Comments
 (0)