Skip to content

Commit a9cd90b

Browse files
authored
Merge pull request #235 from NotedSalmon/FISH-9716-fetch-payara-micro-version-from-maven-central
FISH-9716 fetch payara micro version from maven central
2 parents 1820c3a + 228df3c commit a9cd90b

1 file changed

Lines changed: 51 additions & 14 deletions

File tree

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

Lines changed: 51 additions & 14 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
@@ -25,24 +25,60 @@ 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-
];
35+
const DEFAULT_REPOSITORY_URL = "https://repo1.maven.org/maven2/";
36+
const METADATA_URL = "fish/payara/extras/payara-micro/maven-metadata.xml";
37+
38+
let versions: string[] | null = null;
39+
40+
export async function getPayaraMicroVersions(): Promise<string[]>{
41+
// Check if versions is populated already
42+
if (versions) {
43+
return versions;
44+
}
45+
46+
try {
47+
// Build full URL
48+
const urlString = DEFAULT_REPOSITORY_URL + METADATA_URL;
49+
50+
// Open connection and check response
51+
const response = await fetch(urlString, {method: 'GET'});
52+
if (!response.ok) {
53+
throw new Error('HTTP error! Status: ${response.status}');
54+
}
55+
const xmlResponse = await response.text();
56+
57+
// Parse the XML response using parseStringPromise
58+
const xmlDoc = await parseStringPromise(xmlResponse);
59+
const latest = xmlDoc.metadata.versioning[0].latest[0] || '';
60+
61+
// Extract Versions
62+
const versionNodes = xmlDoc.metadata.versioning[0].versions[0].version;
63+
const fetchedVersions: string[] = [];
64+
65+
for (let i = versionNodes.length - 1; i >= 0; i--) {
66+
const version = versionNodes[i] || '';
67+
if ((version.includes("Alpha") || version.includes("Beta") || version.includes("SNAPSHOT")) && version !== latest) {
68+
continue;
69+
}
70+
fetchedVersions.push(version);
71+
}
72+
73+
versions = fetchedVersions;
74+
75+
return versions;
76+
77+
} catch (e) {
78+
console.error("Error fetching Payara Micro versions:",e);
79+
throw e;
80+
}
81+
}
4682

4783
export class PayaraMicroProjectGenerator {
4884

@@ -161,7 +197,8 @@ export class PayaraMicroProjectGenerator {
161197
}
162198

163199
private async payaraMicroVersion(input: ui.MultiStepInput, project: Partial<PayaraMicroProject>, callback: (n: Partial<PayaraMicroProject>) => any) {
164-
let versions = PAYARA_MICRO_VERSIONS.map(label => ({ label }));
200+
let fetchedVersions = await getPayaraMicroVersions();
201+
let versions = fetchedVersions.map(version => ({ label:version }));
165202
const pick = await input.showQuickPick({
166203
title: TITLE,
167204
step: 6,

0 commit comments

Comments
 (0)