@@ -22,12 +22,15 @@ import * as https from 'https';
22
22
import * as child_process from 'child_process' ;
23
23
import * as vscode from 'vscode' ;
24
24
import * as crypto from 'crypto' ;
25
- import { JDK_RELEASES_TRACK_URL , OPEN_JDK_VERSION_DOWNLOAD_LINKS , ORACLE_JDK_BASE_DOWNLOAD_URL , ORACLE_JDK_VERSION_FALLBACK_DOWNLOAD_VERSIONS } from './constants' ;
26
25
import { handleLog } from './extension' ;
27
26
import { promisify } from 'util' ;
27
+ import * as glob from 'glob' ;
28
28
29
29
let customView : vscode . WebviewPanel ;
30
30
let logger : vscode . OutputChannel ;
31
+ let jdkConfContent : any ;
32
+ const JDK_DOWNLOADER_CONF_FILE_PATH = "https://raw.githubusercontent.com/oracle/javavscode/main/vscode/src/jdkDownloaderManagement.json" ;
33
+
31
34
32
35
export const calculateChecksum = async ( filePath : string ) : Promise < string > => {
33
36
const ALGORITHM = 'sha256' ;
@@ -73,38 +76,15 @@ export const fetchDropdownOptions = async () => {
73
76
// Fetch version of the JDK available
74
77
let versions ;
75
78
try {
76
- const response = await axios . get ( JDK_RELEASES_TRACK_URL , { data : { ResponseType : 'document' } , timeout : 3500 } ) ;
77
- versions = filterLatestJDKVersionsAvail ( response . data . data . releases ) ;
78
- } catch ( error ) {
79
- versions = ORACLE_JDK_VERSION_FALLBACK_DOWNLOAD_VERSIONS ;
80
- handleLog ( logger , "Using fallback versions for oracle JDK" ) ;
79
+ const res = await axios . get ( JDK_DOWNLOADER_CONF_FILE_PATH , { timeout : 4000 } ) ;
80
+ versions = await res . data ;
81
+ } catch ( err : any ) {
82
+ vscode . window . showErrorMessage ( "Error fetching JDK download versions" ) ;
83
+ handleLog ( logger , err ?. messge ) ;
81
84
}
82
-
83
85
return { machineArch, osType, versions } ;
84
86
}
85
87
86
- const filterLatestJDKVersionsAvail = ( json : Array < any > ) => {
87
- const deliveredVersions = json . filter ( release => release . status == "delivered" ) ;
88
-
89
- const sortedVersionWise = deliveredVersions . sort ( ( a , b ) => parseInt ( b . family ) - parseInt ( a . family ) ) ;
90
- const latestVersion = sortedVersionWise [ 0 ] ;
91
-
92
- const ltsVersions = deliveredVersions . filter ( release => {
93
- if ( release . type === "Feature" ) {
94
- const dateDiff : number = new Date ( release . eosl ) . getFullYear ( ) - new Date ( release . ga ) . getFullYear ( ) ;
95
- return dateDiff > 5 ;
96
- }
97
- return false ;
98
- } ) ;
99
-
100
- let latestLtsVersion = sortedVersionWise . filter ( release => release . family === ltsVersions [ 0 ] . family ) [ 0 ] ;
101
- if ( latestLtsVersion . family == latestVersion . family ) {
102
- latestLtsVersion = sortedVersionWise . filter ( release => release . family === ltsVersions [ 1 ] . family ) [ 0 ] ;
103
- }
104
-
105
- return { latestVersion, latestLtsVersion }
106
- }
107
-
108
88
export async function openJDKSelectionView ( log : vscode . OutputChannel ) {
109
89
110
90
// Create JDK Downloader view
@@ -118,6 +98,7 @@ export async function openJDKSelectionView(log: vscode.OutputChannel) {
118
98
) ;
119
99
logger = log ;
120
100
const { machineArch, osType, versions } = await fetchDropdownOptions ( ) ;
101
+ jdkConfContent = versions ;
121
102
customView . webview . html = fetchJDKDownloadView ( machineArch , osType , versions ) ;
122
103
123
104
customView . webview . onDidReceiveMessage ( async message => {
@@ -132,7 +113,7 @@ export async function openJDKSelectionView(log: vscode.OutputChannel) {
132
113
return ;
133
114
}
134
115
135
- vscode . window . showInformationMessage ( `Downloading and completing setup of ${ jdkType } ${ jdkVersion . split ( '.' ) [ 0 ] } ...` ) ;
116
+ vscode . window . showInformationMessage ( `Downloading and completing setup of ${ jdkType } ${ jdkVersion } ...` ) ;
136
117
JDKDownloader ( jdkType , jdkOS , jdkArch , jdkVersion , installationPath ) ;
137
118
}
138
119
}
@@ -143,22 +124,13 @@ export function JDKDownloader(JDKType: string, osType: string, osArchitecture: s
143
124
let downloadUrl : string = '' ;
144
125
145
126
// Generate download url on the basis of the jdk type chosen
146
- if ( JDKType === 'OpenJDK' ) {
147
- if ( osType === 'windows' ) {
148
- downloadUrl = `${ OPEN_JDK_VERSION_DOWNLOAD_LINKS [ `${ JDKVersion } ` ] } _${ osType . toLowerCase ( ) } -${ osArchitecture } _bin.zip` ;
149
- }
150
- else {
151
- downloadUrl = `${ OPEN_JDK_VERSION_DOWNLOAD_LINKS [ `${ JDKVersion } ` ] } _${ osType . toLowerCase ( ) } -${ osArchitecture } _bin.tar.gz` ;
152
- }
127
+ const { baseDownloadUrl } = JDKType === 'OpenJDK' ? jdkConfContent . openJdk [ `${ JDKVersion } ` ] : jdkConfContent . oracleJdk [ `${ JDKVersion } ` ] ;
128
+
129
+ if ( osType === 'windows' ) {
130
+ downloadUrl = `${ baseDownloadUrl } _${ osType . toLowerCase ( ) } -${ osArchitecture } _bin.zip` ;
153
131
}
154
- else if ( JDKType === 'Oracle JDK' ) {
155
- const baseVersion = JDKVersion . split ( '.' ) [ 0 ] ;
156
- if ( osType === 'windows' ) {
157
- downloadUrl = `${ ORACLE_JDK_BASE_DOWNLOAD_URL } /${ baseVersion } /latest/jdk-${ baseVersion } _${ osType . toLowerCase ( ) } -${ osArchitecture } _bin.zip` ;
158
- }
159
- else {
160
- downloadUrl = `${ ORACLE_JDK_BASE_DOWNLOAD_URL } /${ baseVersion } /latest/jdk-${ baseVersion } _${ osType . toLowerCase ( ) } -${ osArchitecture } _bin.tar.gz` ;
161
- }
132
+ else {
133
+ downloadUrl = `${ baseDownloadUrl } _${ osType . toLowerCase ( ) } -${ osArchitecture } _bin.tar.gz` ;
162
134
}
163
135
164
136
// Define the target directory and file name
@@ -215,17 +187,25 @@ export function JDKDownloader(JDKType: string, osType: string, osArchitecture: s
215
187
}
216
188
217
189
export async function extractJDK ( jdkTarballPath : string , extractionTarget : string , jdkVersion : string , osType : string , jdkType : string ) : Promise < void > {
218
- // Extract jdk binaries in a temp folder
219
190
const downloadedDir = path . join ( __dirname , 'jdk_downloads' ) ;
191
+
192
+ // Remove already present version of a particular JDK from temp dir
193
+ const oldTempExtractedDirs = glob . sync ( `jdk-${ jdkVersion } *` , { cwd : downloadedDir } ) ;
194
+ for await ( const oldDirName of oldTempExtractedDirs ) {
195
+ await fs . promises . rmdir ( path . join ( downloadedDir , oldDirName ) , { recursive : true } ) ;
196
+ }
197
+
198
+ // Extract jdk binaries in a temp folder
220
199
const extractCommand = `tar -xzf "${ jdkTarballPath } " -C ${ downloadedDir } ` ;
221
- const tempDirName = `jdk-${ jdkVersion } ${ osType === 'macOS' ? '.jdk' : '' } ` ;
222
- const tempDirectoryPath = path . join ( downloadedDir , tempDirName ) ;
200
+ let tempDirectoryPath : string | null = null ;
223
201
let newDirectoryPath : string | null = null ;
224
202
225
203
child_process . exec ( extractCommand , async ( error ) => {
226
204
if ( error ) {
227
205
vscode . window . showErrorMessage ( 'Error: ' + error ) ;
228
206
} else {
207
+ const tempDirName = glob . sync ( `jdk-${ jdkVersion } *` , { cwd : downloadedDir } ) ?. [ 0 ] ;
208
+ tempDirectoryPath = path . join ( downloadedDir , tempDirName ) ;
229
209
// If directory with same name is present in the user selected download location then ask user if they want to delete it or not?
230
210
const newDirName = `${ jdkType . split ( ' ' ) . join ( '_' ) } -${ jdkVersion } ` ;
231
211
newDirectoryPath = await handleJdkPaths ( newDirName , extractionTarget , osType ) ;
@@ -247,7 +227,7 @@ export async function extractJDK(jdkTarballPath: string, extractionTarget: strin
247
227
if ( err ) {
248
228
vscode . window . showErrorMessage ( "Error: " + err ) ;
249
229
} else {
250
- if ( fs . existsSync ( tempDirectoryPath ) ) {
230
+ if ( tempDirectoryPath && fs . existsSync ( tempDirectoryPath ) ) {
251
231
await fs . promises . rmdir ( tempDirectoryPath , { recursive : true } ) ;
252
232
}
253
233
if ( newDirectoryPath !== null ) {
@@ -421,7 +401,7 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
421
401
</style>
422
402
<body>
423
403
<h1>JDK Downloader</h1>
424
- <p>This tool enables you to download either the Oracle Java SE JDK with <a href="https://www.java.com/freeuselicense"> Oracle No-Fee Terms and Conditions</a> or the Oracle OpenJDK builds under the <a href="http://openjdk.org/legal/gplv2+ce.html">GNU Public License with ClassPath Exception</a>.
404
+ <p>This tool enables you to download either the latest Oracle Java SE JDK with <a href="https://www.java.com/freeuselicense"> Oracle No-Fee Terms and Conditions</a> or the Oracle OpenJDK builds under the <a href="http://openjdk.org/legal/gplv2+ce.html">GNU Public License with ClassPath Exception</a>.
425
405
It will then handle the installation and configuration on your behalf.</p>
426
406
<p>This enables you to take full advantage of all the features offered by this extension.</p>
427
407
<br>
@@ -438,8 +418,12 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
438
418
<br />
439
419
<div class="jdk-version-dropdown">
440
420
<select id="oracleJDKVersionDropdown">
441
- <option value="${ versions . latestVersion . version } " default>JDK ${ versions . latestVersion . family } (${ versions . latestVersion . version } )</option>
442
- <option value="${ versions . latestLtsVersion . version } ">JDK ${ versions . latestLtsVersion . family } (${ versions . latestLtsVersion . version } )</option>
421
+ ${ Object . keys ( versions . oracleJdk ) . sort ( ( a , b ) => parseFloat ( b ) - parseFloat ( a ) ) . map ( ( el , index ) => {
422
+ if ( index === 0 ) {
423
+ return `<option value=${ el } default>JDK ${ el } </option>`
424
+ }
425
+ return `<option value=${ el } >JDK ${ el } </option>`
426
+ } ) }
443
427
</select>
444
428
</div>
445
429
</div>
@@ -474,11 +458,11 @@ export const fetchJDKDownloadView = (machineArch: string, osType: string, versio
474
458
<br />
475
459
<div class="jdk-version-dropdown">
476
460
<select id="openJDKVersionDropdown">
477
- ${ Object . keys ( OPEN_JDK_VERSION_DOWNLOAD_LINKS ) . map ( ( el , index ) => {
461
+ ${ Object . keys ( versions . openJdk ) . sort ( ( a , b ) => parseFloat ( b ) - parseFloat ( a ) ) . map ( ( el , index ) => {
478
462
if ( index === 0 ) {
479
- return `<option value=${ el } default>JDK ${ el . split ( '.' ) [ 0 ] } ( ${ el } ) </option>`
463
+ return `<option value=${ el } default>JDK ${ el } </option>`
480
464
}
481
- return `<option value=${ el } >JDK ${ el . split ( '.' ) [ 0 ] } ( ${ el } ) </option>`
465
+ return `<option value=${ el } >JDK ${ el } </option>`
482
466
} ) }
483
467
</select>
484
468
</div>
0 commit comments