|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | /* |
4 | | - * Copyright (c) 2020 Payara Foundation and/or its affiliates and others. |
| 4 | + * Copyright (c) 2020-2024 Payara Foundation and/or its affiliates and others. |
5 | 5 | * All rights reserved. |
6 | 6 | * |
7 | 7 | * This program and the accompanying materials are made available under the |
@@ -43,6 +43,56 @@ const PAYARA_MICRO_VERSIONS = [ |
43 | 43 | '5.201', '5.194', '5.193.1', '5.192', |
44 | 44 | '5.191', '5.184', '5.183', '5.182', '5.181' |
45 | 45 | ]; |
| 46 | +const DEFAULT_REPOSITORY_URL = "https://repo1.maven.org/maven2/"; |
| 47 | +const METADATA_URL = "fish/payara/extras/payara-micro/maven-metadata.xml"; |
| 48 | + |
| 49 | +let versions: string[] | null = null; |
| 50 | + |
| 51 | +export async function getPayaraMicroVersions(): Promise<string[]>{ |
| 52 | + // Check if versions is populated already |
| 53 | + if (versions) { |
| 54 | + return versions; |
| 55 | + } |
| 56 | + |
| 57 | + try { |
| 58 | + throw new Error('Hello'); |
| 59 | + // Build full URL |
| 60 | + const urlString = DEFAULT_REPOSITORY_URL + METADATA_URL; |
| 61 | + |
| 62 | + // Open connection and check response |
| 63 | + const response = await fetch(urlString, {method: 'GET'}); |
| 64 | + if (!response.ok) { |
| 65 | + throw new Error('HTTP error! Status: ${response.status}'); |
| 66 | + } |
| 67 | + |
| 68 | + const xmlResponse = await response.text(); |
| 69 | + |
| 70 | + // Parse the XML response |
| 71 | + const parser = new DOMParser(); |
| 72 | + const xmlDoc = parser.parseFromString(xmlResponse, "application/xml"); |
| 73 | + |
| 74 | + const latest = xmlDoc.getElementsByTagName("latest")[0]?.textContent || ''; |
| 75 | + |
| 76 | + // Extract Versions |
| 77 | + const versionNodes = xmlDoc.getElementsByTagName("version"); |
| 78 | + const fetchedVersions: string[] = []; |
| 79 | + for (let i = versionNodes.length - 1; i >= 0; i--) { |
| 80 | + const version = versionNodes[i].textContent || ''; |
| 81 | + if ((version.includes("Alpha") || version.includes("Beta") || version.includes("SNAPSHOT")) && version !== latest) { |
| 82 | + continue; |
| 83 | + } |
| 84 | + fetchedVersions.push(version); |
| 85 | + } |
| 86 | + |
| 87 | + versions = fetchedVersions; |
| 88 | + |
| 89 | + return versions; |
| 90 | + |
| 91 | + } catch (e) { |
| 92 | + console.error("Error fetching Payara Micro versions:",e); |
| 93 | + throw e; |
| 94 | + } |
| 95 | +} |
46 | 96 |
|
47 | 97 | export class PayaraMicroProjectGenerator { |
48 | 98 |
|
@@ -161,7 +211,9 @@ export class PayaraMicroProjectGenerator { |
161 | 211 | } |
162 | 212 |
|
163 | 213 | private async payaraMicroVersion(input: ui.MultiStepInput, project: Partial<PayaraMicroProject>, callback: (n: Partial<PayaraMicroProject>) => any) { |
164 | | - let versions = PAYARA_MICRO_VERSIONS.map(label => ({ label })); |
| 214 | + let fetchedVersions = await getPayaraMicroVersions(); |
| 215 | + let versions = fetchedVersions.map(version => ({ label:version })); |
| 216 | + //let versions = PAYARA_MICRO_VERSIONS.map(label => ({ label })); |
165 | 217 | const pick = await input.showQuickPick({ |
166 | 218 | title: TITLE, |
167 | 219 | step: 6, |
|
0 commit comments