diff --git a/vscode/src/constants.ts b/vscode/src/constants.ts new file mode 100644 index 0000000..6d29ad9 --- /dev/null +++ b/vscode/src/constants.ts @@ -0,0 +1,26 @@ +/* + Copyright (c) 2023, Oracle and/or its affiliates. + + 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 + + https://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. +*/ + +export const JDK_RELEASES_TRACK_URL = `https://www.java.com/releases/releases.json`; + +export const ORACLE_JDK_BASE_DOWNLOAD_URL = `https://download.oracle.com/java/`; + +export const ORACLE_JDK_DOWNLOAD_VERSIONS = ['22','21','17']; + +export const OPEN_JDK_VERSION_DOWNLOAD_LINKS: { [key: string]: string } = { + "22": "https://download.java.net/java/GA/jdk22/830ec9fcccef480bb3e73fb7ecafe059/36/GPL/openjdk-22", + "21": "https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2" +}; \ No newline at end of file diff --git a/vscode/src/jdkDownloader.ts b/vscode/src/jdkDownloader.ts index 849404b..f283e38 100644 --- a/vscode/src/jdkDownloader.ts +++ b/vscode/src/jdkDownloader.ts @@ -22,14 +22,12 @@ import * as https from 'https'; import * as child_process from 'child_process'; import * as vscode from 'vscode'; import * as crypto from 'crypto'; +import { OPEN_JDK_VERSION_DOWNLOAD_LINKS, ORACLE_JDK_BASE_DOWNLOAD_URL, ORACLE_JDK_DOWNLOAD_VERSIONS } from './constants'; import { handleLog } from './extension'; import { promisify } from 'util'; let customView: vscode.WebviewPanel; let logger: vscode.OutputChannel; -let jdkConfContent: any; -const JDK_DOWNLOADER_CONF_FILE_PATH = "https://raw.githubusercontent.com/oracle/javavscode/main/vscode/src/jdkDownloaderManagement.json"; - export const calculateChecksum = async (filePath: string): Promise => { const ALGORITHM = 'sha256'; @@ -73,14 +71,8 @@ export const fetchDropdownOptions = async () => { } // Fetch version of the JDK available - let versions; - try { - const res = await axios.get(JDK_DOWNLOADER_CONF_FILE_PATH, { timeout: 4000 }); - versions = await res.data; - } catch (err: any) { - vscode.window.showErrorMessage("Error fetching JDK download versions"); - handleLog(logger, err?.messge); - } + const versions = ORACLE_JDK_DOWNLOAD_VERSIONS; + return { machineArch, osType, versions }; } @@ -97,7 +89,6 @@ export async function openJDKSelectionView(log: vscode.OutputChannel) { ); logger = log; const { machineArch, osType, versions } = await fetchDropdownOptions(); - jdkConfContent = versions; customView.webview.html = fetchJDKDownloadView(machineArch, osType, versions); customView.webview.onDidReceiveMessage(async message => { @@ -123,13 +114,21 @@ export function JDKDownloader(JDKType: string, osType: string, osArchitecture: s let downloadUrl: string = ''; // Generate download url on the basis of the jdk type chosen - const { baseDownloadUrl } = JDKType === 'OpenJDK' ? jdkConfContent.openJdk[`${JDKVersion}`] : jdkConfContent.oracleJdk[`${JDKVersion}`]; - - if (osType === 'windows') { - downloadUrl = `${baseDownloadUrl}_${osType.toLowerCase()}-${osArchitecture}_bin.zip`; + if (JDKType === 'OpenJDK') { + if (osType === 'windows') { + downloadUrl = `${OPEN_JDK_VERSION_DOWNLOAD_LINKS[`${JDKVersion}`]}_${osType.toLowerCase()}-${osArchitecture}_bin.zip`; + } + else { + downloadUrl = `${OPEN_JDK_VERSION_DOWNLOAD_LINKS[`${JDKVersion}`]}_${osType.toLowerCase()}-${osArchitecture}_bin.tar.gz`; + } } - else { - downloadUrl = `${baseDownloadUrl}_${osType.toLowerCase()}-${osArchitecture}_bin.tar.gz`; + else if (JDKType === 'Oracle JDK') { + if (osType === 'windows') { + downloadUrl = `${ORACLE_JDK_BASE_DOWNLOAD_URL}/${JDKVersion}/latest/jdk-${JDKVersion}_${osType.toLowerCase()}-${osArchitecture}_bin.zip`; + } + else { + downloadUrl = `${ORACLE_JDK_BASE_DOWNLOAD_URL}/${JDKVersion}/latest/jdk-${JDKVersion}_${osType.toLowerCase()}-${osArchitecture}_bin.tar.gz`; + } } // Define the target directory and file name @@ -293,7 +292,7 @@ const installationCompletion = async (installType: string) => { } } -export const fetchJDKDownloadView = (machineArch: string, osType: string, versions: any): string => { +export const fetchJDKDownloadView = (machineArch: string, osType: string, versions: Array): string => { return ` JDK Downloader @@ -420,7 +419,7 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
- ${Object.keys(versions.openJdk).sort((a, b) => parseFloat(b)-parseFloat(a)).map((el, index) => { + ${Object.keys(OPEN_JDK_VERSION_DOWNLOAD_LINKS).map((el, index) => { if (index === 0) { return `` } diff --git a/vscode/src/jdkDownloaderManagement.json b/vscode/src/jdkDownloaderManagement.json deleted file mode 100644 index 4710e14..0000000 --- a/vscode/src/jdkDownloaderManagement.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "oracleJdk" : { - "22": { - "baseDownloadUrl":"https://download.oracle.com/java/22/latest/jdk-22" - }, - "21":{ - "baseDownloadUrl":"https://download.oracle.com/java/21/latest/jdk-21" - }, - "17":{ - "baseDownloadUrl":"https://download.oracle.com/java/17/latest/jdk-17" - } - }, - "openJdk" : { - "22" :{ - "baseDownloadUrl":"https://download.java.net/java/GA/jdk22/830ec9fcccef480bb3e73fb7ecafe059/36/GPL/openjdk-22" - }, - "21" : { - "baseDownloadUrl":"https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2" - } - } -} \ No newline at end of file