Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JavaToolInstallerV0] Option for preinstalled JDK #12918

Merged
merged 8 commits into from
May 20, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
"loc.messages.CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode": "Could not fetch access token for Managed Service Principal. Please configure Managed Service Identity (MSI) for virtual machine 'https://aka.ms/azure-msi-docs'. Status code: %s, status message: %s",
"loc.messages.CouldNotFetchAccessTokenforMSIStatusCode": "Could not fetch access token for Managed Service Principal. Status code: %s, status message: %s",
"loc.messages.ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.",
"loc.messages.CorrelationIdForARM": "Correlation ID from ARM api call response : %s"
"loc.messages.CorrelationIdForARM": "Correlation ID from ARM api call response : %s",
anton-erofeev marked this conversation as resolved.
Show resolved Hide resolved
"loc.messages.JavaNotPreinstalled": "Java %s is not preinstalled on this agent"
}
10 changes: 9 additions & 1 deletion Tasks/JavaToolInstallerV0/javatoolinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ async function run() {
}

async function getJava(versionSpec: string) {
const preInstalled: boolean = ("PreInstalled" === taskLib.getInput('jdkSourceOption', true));
const fromAzure: boolean = ('AzureStorage' == taskLib.getInput('jdkSourceOption', true));
const extractLocation: string = taskLib.getPathInput('jdkDestinationDirectory', true);
const cleanDestinationDirectory: boolean = taskLib.getBoolInput('cleanDestinationDirectory', false);
let compressedFileExtension: string;
let jdkDirectory: string;
const extendedJavaHome: string = `JAVA_HOME_${versionSpec}_${taskLib.getInput('jdkArchitectureOption', true)}`;

toolLib.debug('Trying to get tool from local cache first');
const localVersions: string[] = toolLib.findLocalToolVersions('Java');
Expand All @@ -43,6 +45,13 @@ async function getJava(versionSpec: string) {

if (version) { //This version of Java JDK is already in the cache. Use it instead of downloading again.
console.log(taskLib.loc('Info_ResolvedToolFromCache', version));
} else if (preInstalled) {
toolLib.debug("Use preinstalled java");
anton-erofeev marked this conversation as resolved.
Show resolved Hide resolved
const preInstalledJavaDirectory: string | undefined = taskLib.getVariable(extendedJavaHome);
if (preInstalledJavaDirectory === undefined) {
throw new Error(taskLib.loc('JavaNotPreinstalled', versionSpec));
}
jdkDirectory = preInstalledJavaDirectory;
} else if (fromAzure) { //Download JDK from an Azure blob storage location and extract.
console.log(taskLib.loc('RetrievingJdkFromAzure'));
const fileNameAndPath: string = taskLib.getInput('azureCommonVirtualFile', false);
Expand All @@ -63,7 +72,6 @@ async function getJava(versionSpec: string) {
jdkDirectory = await javaFilesExtractor.unzipJavaDownload(taskLib.getInput('jdkFile', true), compressedFileExtension, extractLocation);
}

let extendedJavaHome = 'JAVA_HOME_' + versionSpec + '_' + taskLib.getInput('jdkArchitectureOption', true);
console.log(taskLib.loc('SetJavaHome', jdkDirectory));
console.log(taskLib.loc('SetExtendedJavaHome', extendedJavaHome, jdkDirectory));
taskLib.setVariable('JAVA_HOME', jdkDirectory);
Expand Down
12 changes: 8 additions & 4 deletions Tasks/JavaToolInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 167,
"Patch": 1
"Minor": 170,
"Patch": 0
},
"satisfies": [
"Java"
Expand Down Expand Up @@ -55,7 +55,8 @@
"required": true,
"options": {
"AzureStorage": "Azure Storage",
"LocalDirectory": "Local Directory"
"LocalDirectory": "Local Directory",
"PreInstalled": "Pre-installed"
},
"helpMarkDown": "Source for the compressed JDK."
},
Expand Down Expand Up @@ -111,6 +112,7 @@
"label": "Destination directory",
"defaultValue": "",
"required": true,
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "Destination directory into which JDK should be extracted."
},
{
Expand All @@ -119,6 +121,7 @@
"label": "Clean destination directory",
"required": true,
"defaultValue": "true",
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "Select this option to clean the destination directory before JDK is extracted into it."
}
],
Expand Down Expand Up @@ -171,6 +174,7 @@
"CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode": "Could not fetch access token for Managed Service Principal. Please configure Managed Service Identity (MSI) for virtual machine 'https://aka.ms/azure-msi-docs'. Status code: %s, status message: %s",
"CouldNotFetchAccessTokenforMSIStatusCode": "Could not fetch access token for Managed Service Principal. Status code: %s, status message: %s",
"ExpiredServicePrincipal": "Could not fetch access token for Azure. Verify if the Service Principal used is valid and not expired.",
"CorrelationIdForARM": "Correlation ID from ARM api call response : %s"
"CorrelationIdForARM": "Correlation ID from ARM api call response : %s",
"JavaNotPreinstalled": "Java %s is not preinstalled on this agent"
}
}
12 changes: 8 additions & 4 deletions Tasks/JavaToolInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 167,
"Patch": 1
"Minor": 170,
"Patch": 0
},
"satisfies": [
"Java"
Expand Down Expand Up @@ -55,7 +55,8 @@
"required": true,
"options": {
"AzureStorage": "Azure Storage",
"LocalDirectory": "Local Directory"
"LocalDirectory": "Local Directory",
"PreInstalled": "Pre-installed"
},
"helpMarkDown": "ms-resource:loc.input.help.jdkSourceOption"
},
Expand Down Expand Up @@ -111,6 +112,7 @@
"label": "ms-resource:loc.input.label.jdkDestinationDirectory",
"defaultValue": "",
"required": true,
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "ms-resource:loc.input.help.jdkDestinationDirectory"
},
{
Expand All @@ -119,6 +121,7 @@
"label": "ms-resource:loc.input.label.cleanDestinationDirectory",
"required": true,
"defaultValue": "true",
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "ms-resource:loc.input.help.cleanDestinationDirectory"
}
],
Expand Down Expand Up @@ -171,6 +174,7 @@
"CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode": "ms-resource:loc.messages.CouldNotFetchAccessTokenforMSIDueToMSINotConfiguredProperlyStatusCode",
"CouldNotFetchAccessTokenforMSIStatusCode": "ms-resource:loc.messages.CouldNotFetchAccessTokenforMSIStatusCode",
"ExpiredServicePrincipal": "ms-resource:loc.messages.ExpiredServicePrincipal",
"CorrelationIdForARM": "ms-resource:loc.messages.CorrelationIdForARM"
"CorrelationIdForARM": "ms-resource:loc.messages.CorrelationIdForARM",
"JavaNotPreinstalled": "ms-resource:loc.messages.JavaNotPreinstalled"
}
}