Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions vscode/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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"
};
41 changes: 20 additions & 21 deletions vscode/src/jdkDownloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
const ALGORITHM = 'sha256';
Expand Down Expand Up @@ -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 };
}

Expand All @@ -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 => {
Expand All @@ -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
Expand Down Expand Up @@ -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>): string => {
return `<!DOCTYPE html>
<head>
<title>JDK Downloader</title>
Expand Down Expand Up @@ -420,7 +419,7 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
<br />
<div class="jdk-version-dropdown">
<select id="oracleJDKVersionDropdown">
${Object.keys(versions.oracleJdk).sort((a, b) => parseFloat(b)-parseFloat(a)).map((el, index) => {
${versions.map((el, index) => {
if (index === 0) {
return `<option value=${el} default>JDK ${el}</option>`
}
Expand Down Expand Up @@ -460,7 +459,7 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
<br />
<div class="jdk-version-dropdown">
<select id="openJDKVersionDropdown">
${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 `<option value=${el} default>JDK ${el}</option>`
}
Expand Down
21 changes: 0 additions & 21 deletions vscode/src/jdkDownloaderManagement.json

This file was deleted.