Skip to content

Commit 7ba321d

Browse files
committed
Fix bundle Adopt JDK API deprecated issue
1 parent d92faf0 commit 7ba321d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/buildSrc/src/main/groovy/com/microsoft/azuretools/plugins/configs/BundleBuildIDEAConfig.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ class BundleBuildIDEAConfig implements JdkUrlConfigurable {
3333

3434
private String[] downloadUrls
3535

36-
String adoptOpenJdkApi = "https://api.adoptopenjdk.net/v2/info/releases/openjdk8?os=windows&arch=x64&type=jdk&openjdk_impl=hotspot&release=latest"
36+
String adoptOpenJdkApi = "https://api.adoptium.net/v3/info/release_names?" +
37+
"architecture=x64" +
38+
"&" + "image_type=jdk" +
39+
"&" + "jvm_impl=hotspot" +
40+
"&" + "lts=true" +
41+
"&" + "os=windows" +
42+
"&" + "project=jdk" +
43+
"&" + "release_type=ga" +
44+
"&" + "version=%5B1.8%2C%209%29"
3745

3846
// Version selection
3947
String winutilsVer = "hadoop-2.7.1"

PluginsAndFeatures/azure-toolkit-for-intellij/buildSrc/src/main/groovy/com/microsoft/azuretools/plugins/tasks/FetchAdoptOpenJdkAndSetJdkUrlTask.groovy

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import groovy.json.JsonSlurper
2727
import org.gradle.api.DefaultTask
2828
import org.gradle.api.tasks.TaskAction
2929

30+
import javax.net.ssl.HttpsURLConnection
31+
3032
class FetchAdoptOpenJdkAndSetJdkUrlTask extends DefaultTask {
3133
boolean setOnlyForEmpty = true
3234

@@ -46,8 +48,22 @@ class FetchAdoptOpenJdkAndSetJdkUrlTask extends DefaultTask {
4648

4749
def httpcon = new URL(adoptOpenJdkApi).openConnection()
4850
httpcon.addRequestProperty("User-Agent", "Mozilla")
51+
httpcon.addRequestProperty("accept", "application/json")
52+
4953
def adoptOpenJdk = new JsonSlurper().parseText(httpcon.getInputStream().getText())
5054

51-
conf.jdkUrl = adoptOpenJdk["binaries"][0]["binary_link"]
55+
def latestRelease = adoptOpenJdk["releases"][0]
56+
def jdkUrl = "https://api.adoptium.net/v3/binary/version/" +
57+
latestRelease +
58+
"/windows/x64/jdk/hotspot/normal/eclipse?project=jdk"
59+
60+
HttpURLConnection jdkUrlCon = new URL(jdkUrl).openConnection()
61+
jdkUrlCon.setInstanceFollowRedirects(false)
62+
jdkUrlCon.setRequestMethod("HEAD")
63+
if (jdkUrlCon.getResponseCode() == 307) {
64+
conf.jdkUrl = jdkUrlCon.getHeaderField("Location")
65+
} else {
66+
conf.jdkUrl = jdkUrl
67+
}
5268
}
5369
}

0 commit comments

Comments
 (0)