Skip to content

Commit 228df3c

Browse files
committed
FISH-9716 updated function to use xml2js parser and tested the functionality.
1 parent c6484c4 commit 228df3c

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,13 @@ import { Maven } from '../project/Maven';
2525
import { OpenDialogOptions, Uri, WorkspaceFolder } from 'vscode';
2626
import { PayaraMicroProject } from './PayaraMicroProject';
2727
import { PayaraMicroInstanceController } from './PayaraMicroInstanceController';
28+
import { parseStringPromise } from "xml2js";
2829

2930
const TITLE = 'Generate a Payara Micro project';
3031
const TOTAL_STEP = 7;
3132
const DEFAULT_VERSION: string = '1.0.0-SNAPSHOT';
3233
const DEFAULT_ARTIFACT_ID: string = 'payara-micro-sample';
3334
const DEFAULT_GROUP_ID: string = 'fish.payara.micro.sample';
34-
const PAYARA_MICRO_VERSIONS = [
35-
'6.2023.1', '6.2022.2', '6.2022.1',
36-
'5.2022.5', '5.2022.4', '5.2022.3',
37-
'5.2022.2', '5.2022.1', '5.2021.10',
38-
'5.2021.9', '5.2021.8', '5.2021.7',
39-
'5.2021.6', '5.2021.5', '5.2021.4',
40-
'5.2021.3', '5.2021.2', '5.2021.1',
41-
'5.2020.7', '5.2020.6', '5.2020.5',
42-
'5.2020.4', '5.2020.3', '5.2020.2',
43-
'5.201', '5.194', '5.193.1', '5.192',
44-
'5.191', '5.184', '5.183', '5.182', '5.181'
45-
];
4635
const DEFAULT_REPOSITORY_URL = "https://repo1.maven.org/maven2/";
4736
const METADATA_URL = "fish/payara/extras/payara-micro/maven-metadata.xml";
4837

@@ -55,29 +44,26 @@ export async function getPayaraMicroVersions(): Promise<string[]>{
5544
}
5645

5746
try {
58-
throw new Error('Hello');
5947
// Build full URL
6048
const urlString = DEFAULT_REPOSITORY_URL + METADATA_URL;
61-
49+
6250
// Open connection and check response
6351
const response = await fetch(urlString, {method: 'GET'});
6452
if (!response.ok) {
6553
throw new Error('HTTP error! Status: ${response.status}');
6654
}
67-
6855
const xmlResponse = await response.text();
6956

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 || '';
57+
// Parse the XML response using parseStringPromise
58+
const xmlDoc = await parseStringPromise(xmlResponse);
59+
const latest = xmlDoc.metadata.versioning[0].latest[0] || '';
7560

7661
// Extract Versions
77-
const versionNodes = xmlDoc.getElementsByTagName("version");
62+
const versionNodes = xmlDoc.metadata.versioning[0].versions[0].version;
7863
const fetchedVersions: string[] = [];
64+
7965
for (let i = versionNodes.length - 1; i >= 0; i--) {
80-
const version = versionNodes[i].textContent || '';
66+
const version = versionNodes[i] || '';
8167
if ((version.includes("Alpha") || version.includes("Beta") || version.includes("SNAPSHOT")) && version !== latest) {
8268
continue;
8369
}
@@ -213,7 +199,6 @@ export class PayaraMicroProjectGenerator {
213199
private async payaraMicroVersion(input: ui.MultiStepInput, project: Partial<PayaraMicroProject>, callback: (n: Partial<PayaraMicroProject>) => any) {
214200
let fetchedVersions = await getPayaraMicroVersions();
215201
let versions = fetchedVersions.map(version => ({ label:version }));
216-
//let versions = PAYARA_MICRO_VERSIONS.map(label => ({ label }));
217202
const pick = await input.showQuickPick({
218203
title: TITLE,
219204
step: 6,

0 commit comments

Comments
 (0)