Skip to content

Commit add62b5

Browse files
authored
Fix arm64 JAVA_HOME (#21313)
* arm64 support in JavaToolInstaller * remove usage of common-package * arm64fix for JavaToolInstallerV0 * add comment
1 parent e9b709d commit add62b5

File tree

8 files changed

+33
-15
lines changed

8 files changed

+33
-15
lines changed

Tasks/JavaToolInstallerV0/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"loc.input.label.versionSpec": "JDK version",
88
"loc.input.help.versionSpec": "A number that specifies the JDK version to make available on the path. Use a whole number version, such as 10",
99
"loc.input.label.jdkArchitectureOption": "JDK architecture",
10-
"loc.input.help.jdkArchitectureOption": "The architecture (x86, x64) of the JDK.",
10+
"loc.input.help.jdkArchitectureOption": "The architecture (x86, x64, arm64) of the JDK.",
1111
"loc.input.label.jdkSourceOption": "JDK source",
1212
"loc.input.help.jdkSourceOption": "Source for the compressed JDK.",
1313
"loc.input.label.jdkFile": "JDK file",

Tasks/JavaToolInstallerV0/javatoolinstaller.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
3535
let compressedFileExtension: string;
3636
let jdkDirectory: string;
3737
const extendedJavaHome: string = `JAVA_HOME_${versionSpec}_${jdkArchitectureOption}`.toUpperCase();
38+
const extendedARMJavaHome: string = `JAVA_HOME_${versionSpec}_${jdkArchitectureOption.toLowerCase()}`;
3839

3940
toolLib.debug('Trying to get tool from local cache first');
4041
const localVersions: string[] = toolLib.findLocalToolVersions('Java');
@@ -43,7 +44,13 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
4344
if (version) { //This version of Java JDK is already in the cache. Use it instead of downloading again.
4445
console.log(taskLib.loc('Info_ResolvedToolFromCache', version));
4546
} else if (preInstalled) {
46-
const preInstalledJavaDirectory: string | undefined = taskLib.getVariable(extendedJavaHome);
47+
let preInstalledJavaDirectory: string | undefined = taskLib.getVariable(extendedJavaHome);
48+
// MS-hosted runners set JAVA_HOME_<version>_arm64 variable for pre-installed ARM JDKs.
49+
// If JAVA_HOME_<version>_ARM64 is not found, search for JAVA_HOME_<version>_arm64.
50+
if (!preInstalledJavaDirectory) {
51+
// Using process.env to read the environment variable as taskLib.getVariable converts the name to upper case.
52+
preInstalledJavaDirectory = process.env[extendedARMJavaHome];
53+
}
4754
if (!preInstalledJavaDirectory) {
4855
throw new Error(taskLib.loc('JavaNotPreinstalled', versionSpec));
4956
}
@@ -60,7 +67,7 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
6067
const fileNameAndPath: string = taskLib.getInput('azureCommonVirtualFile', true);
6168
const azureDownloader = new AzureStorageArtifactDownloader(
6269
taskLib.getInput('azureResourceManagerEndpoint', true),
63-
taskLib.getInput('azureStorageAccountName', true),
70+
taskLib.getInput('azureStorageAccountName', true),
6471
taskLib.getInput('azureContainerName', true),
6572
"",
6673
taskLib.getInput('azureResourceGroupName', false),

Tasks/JavaToolInstallerV0/task.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 263,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"satisfies": [
2020
"Java",
@@ -45,10 +45,11 @@
4545
"label": "JDK architecture",
4646
"options": {
4747
"x64": "X64",
48-
"x86": "X86"
48+
"x86": "X86",
49+
"arm64": "arm64"
4950
},
5051
"required": true,
51-
"helpMarkDown": "The architecture (x86, x64) of the JDK."
52+
"helpMarkDown": "The architecture (x86, x64, arm64) of the JDK."
5253
},
5354
{
5455
"name": "jdkSourceOption",

Tasks/JavaToolInstallerV0/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 0,
1616
"Minor": 263,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"satisfies": [
2020
"Java",
@@ -45,7 +45,8 @@
4545
"label": "ms-resource:loc.input.label.jdkArchitectureOption",
4646
"options": {
4747
"x64": "X64",
48-
"x86": "X86"
48+
"x86": "X86",
49+
"arm64": "arm64"
4950
},
5051
"required": true,
5152
"helpMarkDown": "ms-resource:loc.input.help.jdkArchitectureOption"

Tasks/JavaToolInstallerV1/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"loc.input.label.versionSpec": "JDK version",
88
"loc.input.help.versionSpec": "A number that specifies the JDK version to make available on the path. Use a whole number version, such as 10",
99
"loc.input.label.jdkArchitectureOption": "JDK architecture",
10-
"loc.input.help.jdkArchitectureOption": "The architecture (x86, x64) of the JDK.",
10+
"loc.input.help.jdkArchitectureOption": "The architecture (x86, x64, arm64) of the JDK.",
1111
"loc.input.label.jdkSourceOption": "JDK source",
1212
"loc.input.help.jdkSourceOption": "Source for the compressed JDK.",
1313
"loc.input.label.jdkFile": "JDK file",

Tasks/JavaToolInstallerV1/javatoolinstaller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
3535
let compressedFileExtension: string;
3636
let jdkDirectory: string;
3737
const extendedJavaHome: string = `JAVA_HOME_${versionSpec}_${jdkArchitectureOption}`.toUpperCase();
38+
const extendedARMJavaHome: string = `JAVA_HOME_${versionSpec}_${jdkArchitectureOption.toLowerCase()}`;
3839

3940
toolLib.debug('Trying to get tool from local cache first');
4041
const localVersions: string[] = toolLib.findLocalToolVersions('Java');
@@ -43,7 +44,13 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
4344
if (version) { //This version of Java JDK is already in the cache. Use it instead of downloading again.
4445
console.log(taskLib.loc('Info_ResolvedToolFromCache', version));
4546
} else if (preInstalled) {
46-
const preInstalledJavaDirectory: string | undefined = taskLib.getVariable(extendedJavaHome);
47+
let preInstalledJavaDirectory: string | undefined = taskLib.getVariable(extendedJavaHome);
48+
// MS-hosted runners set JAVA_HOME_<version>_arm64 variable for pre-installed ARM JDKs.
49+
// If JAVA_HOME_<version>_ARM64 is not found, search for JAVA_HOME_<version>_arm64.
50+
if (!preInstalledJavaDirectory) {
51+
// Using process.env to read the environment variable as taskLib.getVariable converts the name to upper case.
52+
preInstalledJavaDirectory = process.env[extendedARMJavaHome];
53+
}
4754
if (!preInstalledJavaDirectory) {
4855
throw new Error(taskLib.loc('JavaNotPreinstalled', versionSpec));
4956
}

Tasks/JavaToolInstallerV1/task.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 263,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"satisfies": [
2020
"Java",
@@ -45,10 +45,11 @@
4545
"label": "JDK architecture",
4646
"options": {
4747
"x64": "X64",
48-
"x86": "X86"
48+
"x86": "X86",
49+
"arm64": "arm64"
4950
},
5051
"required": true,
51-
"helpMarkDown": "The architecture (x86, x64) of the JDK."
52+
"helpMarkDown": "The architecture (x86, x64, arm64) of the JDK."
5253
},
5354
{
5455
"name": "jdkSourceOption",

Tasks/JavaToolInstallerV1/task.loc.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 1,
1616
"Minor": 263,
17-
"Patch": 0
17+
"Patch": 1
1818
},
1919
"satisfies": [
2020
"Java",
@@ -45,7 +45,8 @@
4545
"label": "ms-resource:loc.input.label.jdkArchitectureOption",
4646
"options": {
4747
"x64": "X64",
48-
"x86": "X86"
48+
"x86": "X86",
49+
"arm64": "arm64"
4950
},
5051
"required": true,
5152
"helpMarkDown": "ms-resource:loc.input.help.jdkArchitectureOption"

0 commit comments

Comments
 (0)