@@ -29,11 +29,12 @@ public class FoojayJdkInstaller implements JdkInstaller {
2929 protected final JdkProvider jdkProvider ;
3030 protected final Function <JdkResult , String > jdkId ;
3131 protected RemoteAccessProvider remoteAccessProvider ;
32- protected String distro = DEFAULT_DISTRO ;
32+ protected String distros = DEFAULT_DISTROS ;
3333
3434 public static final String FOOJAY_JDK_VERSIONS_URL = "https://api.foojay.io/disco/v3.0/packages?" ;
35+ public static final String FOOJAY_JDK_DISTROS_URL = "https://api.foojay.io/disco/v3.0/distributions?include_versions=false&include_synonyms=false" ;
3536
36- public static final String DEFAULT_DISTRO = "temurin,aoj" ;
37+ public static final String DEFAULT_DISTROS = "temurin,aoj" ;
3738
3839 private static final Logger LOGGER = Logger .getLogger (FoojayJdkInstaller .class .getName ());
3940
@@ -55,6 +56,15 @@ public static class VersionsResponse {
5556 public List <JdkResult > result ;
5657 }
5758
59+ public static class DistroResult {
60+ public String name ;
61+ public String api_parameter ;
62+ }
63+
64+ public static class DistrosResponse {
65+ public List <DistroResult > result ;
66+ }
67+
5868 public FoojayJdkInstaller (@ NonNull JdkProvider jdkProvider ) {
5969 this .jdkProvider = jdkProvider ;
6070 this .jdkId = jdk -> determineId (jdk ) + "-" + jdkProvider .name ();
@@ -77,8 +87,8 @@ public FoojayJdkInstaller(@NonNull JdkProvider jdkProvider, @NonNull Function<Jd
7787 return this ;
7888 }
7989
80- public @ NonNull FoojayJdkInstaller distro (String distro ) {
81- this .distro = distro != null && !distro .isEmpty () ? distro : DEFAULT_DISTRO ;
90+ public @ NonNull FoojayJdkInstaller distros (String distros ) {
91+ this .distros = distros != null && !distros .isEmpty () ? distros : DEFAULT_DISTROS ;
8292 return this ;
8393 }
8494
@@ -95,8 +105,8 @@ public Stream<Jdk.AvailableJdk> listAvailable() {
95105 }
96106
97107 private VersionsResponse readPackagesForList () throws IOException {
98- return readJsonFromUrl (
99- getVersionsUrl (0 , true , OsUtils .getOS (), OsUtils .getArch (), distro , "ga,ea" ));
108+ return readVersionsFromUrl (
109+ getVersionsUrl (0 , true , OsUtils .getOS (), OsUtils .getArch (), distros , "ga,ea" ));
100110 }
101111
102112 @ Override
@@ -129,11 +139,11 @@ private VersionsResponse readPackagesForList() throws IOException {
129139 }
130140
131141 private VersionsResponse readPackagesForVersion (Integer minVersion , boolean openVersion ) throws IOException {
132- VersionsResponse res = readJsonFromUrl (
133- getVersionsUrl (minVersion , openVersion , OsUtils .getOS (), OsUtils .getArch (), distro , "ga" ));
142+ VersionsResponse res = readVersionsFromUrl (
143+ getVersionsUrl (minVersion , openVersion , OsUtils .getOS (), OsUtils .getArch (), distros , "ga" ));
134144 if (res .result .isEmpty ()) {
135- res = readJsonFromUrl (
136- getVersionsUrl (minVersion , openVersion , OsUtils .getOS (), OsUtils .getArch (), distro , "ea" ));
145+ res = readVersionsFromUrl (
146+ getVersionsUrl (minVersion , openVersion , OsUtils .getOS (), OsUtils .getArch (), distros , "ea" ));
137147 }
138148 return res ;
139149 }
@@ -176,7 +186,7 @@ private Stream<Jdk.AvailableJdk> processPackages(List<JdkResult> jdks, Comparato
176186 return tags ;
177187 }
178188
179- private VersionsResponse readJsonFromUrl (String url ) throws IOException {
189+ private VersionsResponse readVersionsFromUrl (String url ) throws IOException {
180190 return RemoteAccessProvider .readJsonFromUrl (remoteAccessProvider (), url , VersionsResponse .class );
181191 }
182192
@@ -209,7 +219,7 @@ private List<JdkResult> filterEA(List<JdkResult> jdks) {
209219 .compare (o1 .java_version , o2 .java_version );
210220
211221 private Comparator <JdkResult > majorVersionSort () {
212- List <String > ds = Arrays .asList (distro .split ("," ));
222+ List <String > ds = Arrays .asList (distros .split ("," ));
213223 Comparator <JdkResult > jdkResultDistroComparator = Comparator .comparingInt (o -> ds .indexOf (o .distribution ));
214224 return Comparator
215225 .comparingInt ((JdkResult jdk ) -> -jdk .major_version )
@@ -256,13 +266,27 @@ public void uninstall(Jdk.@NonNull InstalledJdk jdk) {
256266 JavaUtils .safeDeleteJdk (jdk .home ());
257267 }
258268
269+ @ Override
270+ public List <JdkDistro > listDistros () {
271+ try {
272+ DistrosResponse response = RemoteAccessProvider .readJsonFromUrl (remoteAccessProvider (),
273+ FOOJAY_JDK_DISTROS_URL , DistrosResponse .class );
274+ return response .result .stream ()
275+ .map (d -> new JdkDistro (d .api_parameter ))
276+ .collect (Collectors .toList ());
277+ } catch (IOException e ) {
278+ LOGGER .log (Level .FINE , "Couldn't list available JDKs" , e );
279+ return Collections .emptyList ();
280+ }
281+ }
282+
259283 private static String getVersionsUrl (int minVersion , boolean openVersion , OsUtils .OS os , OsUtils .Arch arch ,
260- String distro , String status ) {
261- return FOOJAY_JDK_VERSIONS_URL + getUrlParams (minVersion , openVersion , os , arch , distro , status );
284+ String distros , String status ) {
285+ return FOOJAY_JDK_VERSIONS_URL + getUrlParams (minVersion , openVersion , os , arch , distros , status );
262286 }
263287
264288 private static String getUrlParams (int version , boolean openVersion , OsUtils .OS os , OsUtils .Arch arch ,
265- String distro , String status ) {
289+ String distros , String status ) {
266290 Map <String , String > params = new HashMap <>();
267291 if (version > 0 ) {
268292 String v = String .valueOf (version );
@@ -272,14 +296,14 @@ private static String getUrlParams(int version, boolean openVersion, OsUtils.OS
272296 params .put ("version" , v );
273297 }
274298
275- if (distro == null ) {
299+ if (distros == null ) {
276300 if (version == 0 || version == 8 || version == 11 || version >= 17 ) {
277- distro = "temurin" ;
301+ distros = "temurin" ;
278302 } else {
279- distro = "aoj" ;
303+ distros = "aoj" ;
280304 }
281305 }
282- params .put ("distro" , distro );
306+ params .put ("distro" , distros );
283307
284308 String archiveType ;
285309 if (os == OsUtils .OS .windows ) {
@@ -357,7 +381,7 @@ public static class Discovery implements JdkInstallers.Discovery {
357381 @ Override
358382 public @ NonNull JdkInstaller create (Config config ) {
359383 FoojayJdkInstaller installer = new FoojayJdkInstaller (config .jdkProvider ());
360- installer .distro (config .properties ().getOrDefault ("distro" , null ));
384+ installer .distros (config .properties ().getOrDefault ("distro" , null ));
361385 HttpClientBuilder httpClientBuilder = NetUtils .createCachingHttpClientBuilder (config .cachePath ());
362386 RemoteAccessProvider rap = RemoteAccessProvider .createDefaultRemoteAccessProvider (httpClientBuilder );
363387 installer .remoteAccessProvider (rap );
0 commit comments