()
| 22 | } |
| 23 | |
| 24 | public async setupJava(): Promise<JavaInstallerResults> { |
| 25 | let foundJava = this.findInToolcache(); |
| 26 | |
| 27 | if (foundJava) { |
| 28 | core.info(`Resolved Java ${foundJava.version} from tool-cache`); |
| 29 | } else { |
| 30 | core.info( |
| 31 | `Java ${this.version} was not found in tool-cache. Trying to unpack JDK file...` |
| 32 | ); |
| 33 | if (!this.jdkFile) { |
| 34 | throw new Error("'jdkFile' is not specified"); |
| 35 | } |
| 36 | const jdkFilePath = path.resolve(this.jdkFile); |
| 37 | const stats = fs.statSync(jdkFilePath); |
| 38 | |
| 39 | if (!stats.isFile()) { |
| 40 | throw new Error(`JDK file was not found in path '${jdkFilePath}'`); |
| 41 | } |
| 42 | |
| 43 | core.info(`Extracting Java from '${jdkFilePath}'`); |
| 44 | |
| 45 | const extractedJavaPath = await extractJdkFile(jdkFilePath); |
| 46 | const archiveName = fs.readdirSync(extractedJavaPath)[0]; |
| 47 | const archivePath = path.join(extractedJavaPath, archiveName); |
| 48 | const javaVersion = this.version; |
| 49 | |
| 50 | const javaPath = await tc.cacheDir( |
| 51 | archivePath, |
| 52 | this.toolcacheFolderName, |
| 53 | this.getToolcacheVersionName(javaVersion), |
| 54 | this.architecture |
| 55 | ); |
| 56 | |
| 57 | foundJava = { |
| 58 | version: javaVersion, |
| 59 | path: javaPath |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | // JDK folder may contain postfix "Contents/Home" on macOS |
| 64 | const macOSPostfixPath = path.join( |
| 65 | foundJava.path, |
| 66 | MACOS_JAVA_CONTENT_POSTFIX |
| 67 | ); |
| 68 | if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) { |
| 69 | foundJava.path = macOSPostfixPath; |
| 70 | } |
| 71 | |
| 72 | core.info(`Setting Java ${foundJava.version} as default`); |
| 73 | |
| 74 | this.setJavaDefault(foundJava.version, foundJava.path); |
| 75 | return foundJava; |
| 76 | } |
| 77 | |
| 78 | protected async findPackageForDownload( |
| 79 | version: string // eslint-disable-line @typescript-eslint/no-unused-vars |
no test coverage detected