Skip to content

Commit 6c5dce6

Browse files
authored
Merge pull request #145 from Achal1607/revert-jdk-downloader-code
revert JDK downloader refactored code
2 parents eee935a + 5386523 commit 6c5dce6

File tree

3 files changed

+46
-42
lines changed

3 files changed

+46
-42
lines changed

vscode/src/constants.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright (c) 2023, Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
export const JDK_RELEASES_TRACK_URL = `https://www.java.com/releases/releases.json`;
18+
19+
export const ORACLE_JDK_BASE_DOWNLOAD_URL = `https://download.oracle.com/java/`;
20+
21+
export const ORACLE_JDK_DOWNLOAD_VERSIONS = ['22','21','17'];
22+
23+
export const OPEN_JDK_VERSION_DOWNLOAD_LINKS: { [key: string]: string } = {
24+
"22": "https://download.java.net/java/GA/jdk22/830ec9fcccef480bb3e73fb7ecafe059/36/GPL/openjdk-22",
25+
"21": "https://download.java.net/java/GA/jdk21.0.2/f2283984656d49d69e91c558476027ac/13/GPL/openjdk-21.0.2"
26+
};

vscode/src/jdkDownloader.ts

+20-21
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ import * as https from 'https';
2222
import * as child_process from 'child_process';
2323
import * as vscode from 'vscode';
2424
import * as crypto from 'crypto';
25+
import { OPEN_JDK_VERSION_DOWNLOAD_LINKS, ORACLE_JDK_BASE_DOWNLOAD_URL, ORACLE_JDK_DOWNLOAD_VERSIONS } from './constants';
2526
import { handleLog } from './extension';
2627
import { promisify } from 'util';
2728

2829
let customView: vscode.WebviewPanel;
2930
let logger: vscode.OutputChannel;
30-
let jdkConfContent: any;
31-
const JDK_DOWNLOADER_CONF_FILE_PATH = "https://raw.githubusercontent.com/oracle/javavscode/main/vscode/src/jdkDownloaderManagement.json";
32-
3331

3432
export const calculateChecksum = async (filePath: string): Promise<string> => {
3533
const ALGORITHM = 'sha256';
@@ -73,14 +71,8 @@ export const fetchDropdownOptions = async () => {
7371
}
7472

7573
// Fetch version of the JDK available
76-
let versions;
77-
try {
78-
const res = await axios.get(JDK_DOWNLOADER_CONF_FILE_PATH, { timeout: 4000 });
79-
versions = await res.data;
80-
} catch (err: any) {
81-
vscode.window.showErrorMessage("Error fetching JDK download versions");
82-
handleLog(logger, err?.messge);
83-
}
74+
const versions = ORACLE_JDK_DOWNLOAD_VERSIONS;
75+
8476
return { machineArch, osType, versions };
8577
}
8678

@@ -97,7 +89,6 @@ export async function openJDKSelectionView(log: vscode.OutputChannel) {
9789
);
9890
logger = log;
9991
const { machineArch, osType, versions } = await fetchDropdownOptions();
100-
jdkConfContent = versions;
10192
customView.webview.html = fetchJDKDownloadView(machineArch, osType, versions);
10293

10394
customView.webview.onDidReceiveMessage(async message => {
@@ -123,13 +114,21 @@ export function JDKDownloader(JDKType: string, osType: string, osArchitecture: s
123114
let downloadUrl: string = '';
124115

125116
// Generate download url on the basis of the jdk type chosen
126-
const { baseDownloadUrl } = JDKType === 'OpenJDK' ? jdkConfContent.openJdk[`${JDKVersion}`] : jdkConfContent.oracleJdk[`${JDKVersion}`];
127-
128-
if (osType === 'windows') {
129-
downloadUrl = `${baseDownloadUrl}_${osType.toLowerCase()}-${osArchitecture}_bin.zip`;
117+
if (JDKType === 'OpenJDK') {
118+
if (osType === 'windows') {
119+
downloadUrl = `${OPEN_JDK_VERSION_DOWNLOAD_LINKS[`${JDKVersion}`]}_${osType.toLowerCase()}-${osArchitecture}_bin.zip`;
120+
}
121+
else {
122+
downloadUrl = `${OPEN_JDK_VERSION_DOWNLOAD_LINKS[`${JDKVersion}`]}_${osType.toLowerCase()}-${osArchitecture}_bin.tar.gz`;
123+
}
130124
}
131-
else {
132-
downloadUrl = `${baseDownloadUrl}_${osType.toLowerCase()}-${osArchitecture}_bin.tar.gz`;
125+
else if (JDKType === 'Oracle JDK') {
126+
if (osType === 'windows') {
127+
downloadUrl = `${ORACLE_JDK_BASE_DOWNLOAD_URL}/${JDKVersion}/latest/jdk-${JDKVersion}_${osType.toLowerCase()}-${osArchitecture}_bin.zip`;
128+
}
129+
else {
130+
downloadUrl = `${ORACLE_JDK_BASE_DOWNLOAD_URL}/${JDKVersion}/latest/jdk-${JDKVersion}_${osType.toLowerCase()}-${osArchitecture}_bin.tar.gz`;
131+
}
133132
}
134133

135134
// Define the target directory and file name
@@ -293,7 +292,7 @@ const installationCompletion = async (installType: string) => {
293292
}
294293
}
295294

296-
export const fetchJDKDownloadView = (machineArch: string, osType: string, versions: any): string => {
295+
export const fetchJDKDownloadView = (machineArch: string, osType: string, versions: Array<String>): string => {
297296
return `<!DOCTYPE html>
298297
<head>
299298
<title>JDK Downloader</title>
@@ -420,7 +419,7 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
420419
<br />
421420
<div class="jdk-version-dropdown">
422421
<select id="oracleJDKVersionDropdown">
423-
${Object.keys(versions.oracleJdk).sort((a, b) => parseFloat(b)-parseFloat(a)).map((el, index) => {
422+
${versions.map((el, index) => {
424423
if (index === 0) {
425424
return `<option value=${el} default>JDK ${el}</option>`
426425
}
@@ -460,7 +459,7 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
460459
<br />
461460
<div class="jdk-version-dropdown">
462461
<select id="openJDKVersionDropdown">
463-
${Object.keys(versions.openJdk).sort((a, b) => parseFloat(b)-parseFloat(a)).map((el, index) => {
462+
${Object.keys(OPEN_JDK_VERSION_DOWNLOAD_LINKS).map((el, index) => {
464463
if (index === 0) {
465464
return `<option value=${el} default>JDK ${el}</option>`
466465
}

vscode/src/jdkDownloaderManagement.json

-21
This file was deleted.

0 commit comments

Comments
 (0)