-
Notifications
You must be signed in to change notification settings - Fork 164
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
Add JdkInstaller #315
Merged
Merged
Add JdkInstaller #315
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
476c550
Add JdkInstaller
joycetoh8 f325592
Fix lint errors
joycetoh8 d7513f5
Update comments and move error to constructor
joycetoh8 b2bd919
Update comments and move error to constructor
joycetoh8 3901b8c
Merge branch 'auto-download-jdk' of github.com:joycetoh8/bubblewrap i…
joycetoh8 af8d130
Fix lint errors
joycetoh8 c795e0e
Modify flow to install JDK to default path
joycetoh8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright 2019 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import * as path from 'path'; | ||
import util = require('../util'); | ||
|
||
const JDK_VERSION = '8u265-b01'; | ||
const JDK_DIR = `jdk${JDK_VERSION}`; | ||
const DOWNLOAD_JDK_BIN_ROOT = `https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk${JDK_VERSION}/`; | ||
const DOWNLOAD_JDK_SRC_ROOT = 'https://github.com/AdoptOpenJDK/openjdk-jdk8u/archive/'; | ||
const JDK_BIN_VERSION = JDK_VERSION.replace('-', ''); | ||
const JDK_FILE_NAME_MAC = `OpenJDK8U-jdk_x64_mac_hotspot_${JDK_BIN_VERSION}.tar.gz`; | ||
const JDK_FILE_NAME_WIN32 = `OpenJDK8U-jdk_x86-32_windows_hotspot_${JDK_BIN_VERSION}.zip`; | ||
const JDK_FILE_NAME_LINUX64 = `OpenJDK8U-jdk_x64_linux_hotspot_${JDK_BIN_VERSION}.tar.gz`; | ||
const JDK_SRC_ZIP = `jdk${JDK_VERSION}.zip`; | ||
|
||
/** | ||
* Checks whether JDK 8 is installed. If not installed, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is wrong isn't it? I can't see where this class checks whether JDK 8 is installed. |
||
* download the binary and source code and decompress at | ||
joycetoh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* path given by user. | ||
joycetoh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
export class JdkInstaller { | ||
private process: NodeJS.Process; | ||
private downloadFile: string; | ||
private unzipFunction: (srcPath: string, dstPath: string, deleteWhenDone: boolean) | ||
=> Promise<void>; | ||
private joinPath: (...paths: string[]) => string; | ||
/** | ||
joycetoh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* Constructs a new instance of JdkInstaller | ||
joycetoh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param process {NodeJS.Process} process information from the OS process | ||
*/ | ||
constructor(process: NodeJS.Process) { | ||
this.process = process; | ||
this.unzipFunction = util.untar; | ||
this.joinPath = path.posix.join; | ||
switch (process.platform) { | ||
case 'win32': { | ||
this.downloadFile = JDK_FILE_NAME_WIN32; | ||
this.unzipFunction = util.unzipFile; | ||
this.joinPath = path.win32.join; | ||
break; | ||
} | ||
case 'darwin': { | ||
this.downloadFile = JDK_FILE_NAME_MAC; | ||
break; | ||
} | ||
case 'linux': { | ||
this.downloadFile = JDK_FILE_NAME_LINUX64; | ||
break; | ||
} | ||
default: | ||
this.downloadFile = ''; | ||
console.log('Platform not found. Cannot download appropriate JDK.'); | ||
joycetoh8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
/** | ||
* Downloads the platform-appropriate version of JDK 8, including | ||
* binary and source code. | ||
* | ||
* @param installPath {string} path to install JDK at | ||
*/ | ||
async install(installPath: string): Promise<string> { | ||
if (this.downloadFile === '') { | ||
throw new Error(`Platform not found or unsupported: ${this.process.platform}.`); | ||
} | ||
const dstPath = path.resolve(installPath); | ||
const downloadSrcUrl = DOWNLOAD_JDK_SRC_ROOT + JDK_SRC_ZIP; | ||
const localSrcZipPath = this.joinPath(dstPath, JDK_SRC_ZIP); | ||
await util.downloadFile(downloadSrcUrl, localSrcZipPath); | ||
await util.unzipFile(localSrcZipPath, dstPath, true); | ||
|
||
const downloadBinUrl = DOWNLOAD_JDK_BIN_ROOT + this.downloadFile; | ||
const localBinPath = this.joinPath(dstPath, this.downloadFile); | ||
await util.downloadFile(downloadBinUrl, localBinPath); | ||
await this.unzipFunction(localBinPath, dstPath, true); | ||
|
||
return this.joinPath(dstPath, JDK_DIR); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wrong year for the copyright header.