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
7 changes: 4 additions & 3 deletions vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export namespace extConstants {
}

export namespace jdkDownloaderConstants {
export const JDK_RELEASES_TRACK_URL = `https://www.java.com/releases/releases.json`;

export const ORACLE_JDK_RELEASES_BASE_URL = `https://java.oraclecloud.com/currentJavaReleases`;

export const ORACLE_JDK_BASE_DOWNLOAD_URL = `https://download.oracle.com/java`;

export const ORACLE_JDK_DOWNLOAD_VERSIONS = ['23', '21'];

export const ORACLE_JDK_FALLBACK_VESIONS = ['24', '21'];
export const OPEN_JDK_VERSION_DOWNLOAD_LINKS: { [key: string]: string } = {
"23": "https://download.java.net/java/GA/jdk23.0.2/6da2a6609d6e406f85c491fcb119101b/7/GPL/openjdk-23.0.2"
};
Expand Down
23 changes: 16 additions & 7 deletions vscode/src/test/unit/webviews/jdkDownloader/view.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as sinon from 'sinon';
import { WebviewPanel, window } from 'vscode';
import { JdkDownloaderView } from '../../../../webviews/jdkDownloader/view';
import { checkTagContentNotEmpty, enableMockedLoggers, getMachineArch, getOsType } from '../../testUtils';
import * as utils from '../../../../utils';

describe('JDK Downloader view tests', () => {
let jdkDownloaderView: JdkDownloaderView;
Expand All @@ -44,6 +45,21 @@ describe('JDK Downloader view tests', () => {
beforeEach(() => {
createWebviewPanelStub = sandbox.stub(window, 'createWebviewPanel');
onDidReceiveMessageStub = sandbox.stub();
let versionsStub: sinon.SinonStub = sandbox.stub(utils, "httpsGet");
versionsStub.returns(`{
"items": [
{
"jdkDetails":{
"jdkVersion": 23
}
},
{
"jdkDetails":{
"jdkVersion": 21
}
}
]
}`);

webviewPanel = {
webview: {
Expand Down Expand Up @@ -132,13 +148,6 @@ describe('JDK Downloader view tests', () => {
expect(jdkDownloaderHtml).to.match(archOptionRegex);
});
});

it("should attach a message listener to the webview", () => {
expect(onDidReceiveMessageStub.calledOnce).to.be.true;
const listener = onDidReceiveMessageStub.firstCall.args[0];
expect(listener).to.be.a('function');
});

});

it("should dispose the webview", () => {
Expand Down
31 changes: 28 additions & 3 deletions vscode/src/webviews/jdkDownloader/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { JdkDownloaderAction } from './action';
import { downloaderCss } from './styles';
import { l10n } from '../../localiser';
import { LOGGER } from '../../logger';
import { httpsGet, isError, isString } from '../../utils';

export class JdkDownloaderView {
public static readonly OPEN_JDK_LABEL = "OpenJDK";
Expand All @@ -31,8 +32,9 @@ export class JdkDownloaderView {
private jdkDownloaderWebView?: WebviewPanel;
private osType?: string;
private machineArch?: string;
private oracleJdkVersions: string[] = [];

public createView = () => {
public createView = async () => {
try {
LOGGER.log("Creating JDK downloader webview");
this.jdkDownloaderWebView = window.createWebviewPanel(
Expand All @@ -43,6 +45,7 @@ export class JdkDownloaderView {
enableScripts: true
}
);
this.oracleJdkVersions = await this.getOracleJdkVersions();
this.setDropdownOptions();
this.jdkDownloaderWebView.webview.html = this.fetchJdkDownloadViewHtml();
this.jdkDownloaderWebView.webview.onDidReceiveMessage(message => {
Expand Down Expand Up @@ -111,7 +114,7 @@ export class JdkDownloaderView {
<br />
<div class="jdk-version-dropdown">
<select id="oracleJDKVersionDropdown">
${this.getJdkVersionsHtml(jdkDownloaderConstants.ORACLE_JDK_DOWNLOAD_VERSIONS)}
${this.getJdkVersionsHtml(this.oracleJdkVersions)}
</select>
</div>
</div>
Expand Down Expand Up @@ -177,7 +180,29 @@ export class JdkDownloaderView {
`
}

private getJdkVersionsHtml = (jdkVersions: String[]) => {
private getOracleJdkVersions = async (): Promise<string[]> => {
try {
LOGGER.log("Fetching Oracle JDK versions...");
const availableVersions = await httpsGet(`${jdkDownloaderConstants.ORACLE_JDK_RELEASES_BASE_URL}?licenseType=NFTC&sortBy=jdkVersion&sortOrder=DESC`);
if (isString(availableVersions)) {
const availableVersionsObj = JSON.parse(availableVersions);
if (availableVersionsObj?.items) {
const jdkVersions = availableVersionsObj?.items?.map((version: any) => version.jdkDetails.jdkVersion);
LOGGER.log(`Fetched Oracle JDK versions: ${jdkVersions}`);

return jdkVersions;
}
}
LOGGER.warn(`Response of Oracle JDK versions is not as expected`);
} catch (error) {
const msg = `Some error occurred while fetching Oracle JDK versions: ${isError(error) ? error.message : null}`;
LOGGER.warn(msg);
}

return jdkDownloaderConstants.ORACLE_JDK_FALLBACK_VESIONS;
}

private getJdkVersionsHtml = (jdkVersions: string[]) => {
let htmlStr = "";
jdkVersions.forEach((el: String, index: number) => {
if (index === 0) {
Expand Down