Skip to content

Commit

Permalink
Allow not to create subdirectory for jdk extraction (#14847)
Browse files Browse the repository at this point in the history
* Add option to not create directory for jdk unpacking

* Regenerated task.loc.json and resjson

* Added test

* Reverted extra change

* Reverted extra changes

* Address review points

* Fix issue with trailing slash in extraction directory

* Fix issue for jdk installation from azure

* Fix nit

Co-authored-by: DaniilShmelev <[email protected]>
  • Loading branch information
EzzhevNikita and DaniilShmelev authored May 20, 2021
1 parent 89dc1ce commit 88a49c4
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
10 changes: 9 additions & 1 deletion Tasks/JavaToolInstallerV0/FileExtractor/JavaFilesExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ export class JavaFilesExtractor {
*/
public static getJavaHomeFromStructure(pathToStructure): string {
const structure: Array<string> = taskLib.find(pathToStructure);
const rootDirectoriesArray: Array<string> = JavaFilesExtractor.sliceStructure(structure);
const rootItemsArray: Array<string> = JavaFilesExtractor.sliceStructure(structure);
const rootDirectoriesArray: Array<string> = new Array<string>();
// it is allowed to have extra files in extraction directory, but we shouldn't have more than 1 directory here
rootItemsArray.forEach(rootItem => {
if (fs.lstatSync(path.join(pathToStructure, rootItem)).isDirectory()) {
rootDirectoriesArray.push(rootItem);
}
});

let jdkDirectory: string;
if (rootDirectoriesArray.find(dir => dir === BIN_FOLDER)){
jdkDirectory = pathToStructure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"loc.input.label.azureCommonVirtualFile": "Common virtual path",
"loc.input.help.azureCommonVirtualFile": "Path to the JDK inside the Azure storage container.",
"loc.input.label.jdkDestinationDirectory": "Destination directory",
"loc.input.help.jdkDestinationDirectory": "On Linux and Windows, this is used as the destination directory for JDK installation. On macOS, this directory is used as a temporary folder for extracting .dmg's since macOS doesn't support installing of JDK to specific directory.",
"loc.input.help.jdkDestinationDirectory": "On Linux and Windows, this is used as the destination directory for JDK installation. On macOS, this directory is used as a temporary folder for extracting of .dmg's since macOS doesn't support installing of JDK to specific directory.",
"loc.input.label.cleanDestinationDirectory": "Clean destination directory",
"loc.input.help.cleanDestinationDirectory": "Select this option to clean the destination directory before JDK is extracted into it.",
"loc.input.label.createExtractDirectory": "Create directory for extracting",
"loc.input.help.createExtractDirectory": "By default, task is creating a directory similar to this JAVA_HOME_8_X64_OpenJDK_zip for extracting JDK. This option allows to disable creation of this folder, in this case, JDK will be located in the root of jdkDestinationDirectory",
"loc.messages.DownloadFromAzureBlobStorage": "Downloading artifacts from Azure blob storage, Container Name: %s",
"loc.messages.SuccessFullyFetchedItemList": "Successfully fetched list of items",
"loc.messages.StorageAccountDoesNotExist": "Failed to get azure storage account with name %s.",
Expand Down
15 changes: 13 additions & 2 deletions Tasks/JavaToolInstallerV0/javatoolinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,20 @@ async function installJDK(sourceFile: string, fileExtension: string, archiveExtr
jdkDirectory = await installPkg(sourceFile, extendedJavaHome, versionSpec);
}
else {
const createExtractDirectory: boolean = taskLib.getBoolInput('createExtractDirectory', false);
let extractionDirectory: string = "";
if (createExtractDirectory) {
const extractDirectoryName: string = `${extendedJavaHome}_${JavaFilesExtractor.getStrippedName(sourceFile)}_${fileExtension.substr(1)}`;
extractionDirectory = path.join(archiveExtractLocation, extractDirectoryName);
} else {
// we need to remove path separator symbol on the end of archiveExtractLocation path since it could produce issues in getJavaHomeFromStructure method
if (archiveExtractLocation.endsWith(path.sep)) {
archiveExtractLocation = archiveExtractLocation.slice(0, -1);
}

extractionDirectory = path.normalize(archiveExtractLocation);
}
// unpack the archive, set `JAVA_HOME` and save it for further processing
const extractDirectoryName: string = `${extendedJavaHome}_${JavaFilesExtractor.getStrippedName(sourceFile)}_${fileExtension.substr(1)}`;
const extractionDirectory: string = path.join(archiveExtractLocation, extractDirectoryName);
await unpackArchive(extractionDirectory, sourceFile, fileExtension, cleanDestinationDirectory);
jdkDirectory = JavaFilesExtractor.setJavaHome(extractionDirectory);
}
Expand Down
13 changes: 11 additions & 2 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": 186,
"Patch": 1
"Minor": 188,
"Patch": 0
},
"satisfies": [
"Java",
Expand Down Expand Up @@ -125,6 +125,15 @@
"defaultValue": "true",
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "Select this option to clean the destination directory before JDK is extracted into it."
},
{
"name": "createExtractDirectory",
"type": "boolean",
"label": "Create directory for extracting",
"required": false,
"defaultValue": true,
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "By default, task is creating a directory similar to this JAVA_HOME_8_X64_OpenJDK_zip for extracting JDK. This option allows to disable creation of this folder, in this case, JDK will be located in the root of jdkDestinationDirectory"
}
],
"dataSourceBindings": [
Expand Down
13 changes: 11 additions & 2 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": 186,
"Patch": 1
"Minor": 188,
"Patch": 0
},
"satisfies": [
"Java",
Expand Down Expand Up @@ -125,6 +125,15 @@
"defaultValue": "true",
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "ms-resource:loc.input.help.cleanDestinationDirectory"
},
{
"name": "createExtractDirectory",
"type": "boolean",
"label": "ms-resource:loc.input.label.createExtractDirectory",
"required": false,
"defaultValue": true,
"visibleRule": "jdkSourceOption != PreInstalled",
"helpMarkDown": "ms-resource:loc.input.help.createExtractDirectory"
}
],
"dataSourceBindings": [
Expand Down

0 comments on commit 88a49c4

Please sign in to comment.