Skip to content

Commit c6484c4

Browse files
committed
FISH-9716 created async function to parse xml data and display them.
1 parent 1820c3a commit c6484c4

1 file changed

Lines changed: 54 additions & 2 deletions

File tree

src/main/fish/payara/micro/PayaraMicroProjectGenerator.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/*
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.
55
* All rights reserved.
66
*
77
* This program and the accompanying materials are made available under the
@@ -43,6 +43,56 @@ const PAYARA_MICRO_VERSIONS = [
4343
'5.201', '5.194', '5.193.1', '5.192',
4444
'5.191', '5.184', '5.183', '5.182', '5.181'
4545
];
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+
}
4696

4797
export class PayaraMicroProjectGenerator {
4898

@@ -161,7 +211,9 @@ export class PayaraMicroProjectGenerator {
161211
}
162212

163213
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 }));
165217
const pick = await input.showQuickPick({
166218
title: TITLE,
167219
step: 6,

0 commit comments

Comments
 (0)