-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use v4 of the MicroProfile starter api (#59)
* Update to use v4 mp starter api * move project generation to starter api helper * Update wording in error messages Signed-off-by: Ryan Zegray <ryan.zegray@gmail.com>
- Loading branch information
Showing
8 changed files
with
151 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { MP_STARTER_API_ROOT, EXTENSION_USER_AGENT } from "../constants"; | ||
import fetch from "node-fetch"; | ||
import * as util from "../util/util"; | ||
|
||
interface MPVersionSupport { | ||
supportedServers: string[]; | ||
specs: string[]; | ||
} | ||
|
||
interface SupportMatrix { | ||
configs: Record<string, MPVersionSupport>; | ||
descriptions: Record<string, string>; | ||
} | ||
|
||
export async function getSupportMatrix(): Promise<SupportMatrix> { | ||
const mpSupportResponse = await fetch(`${MP_STARTER_API_ROOT}/supportMatrix`, { | ||
method: "GET", | ||
headers: { | ||
"User-Agent": EXTENSION_USER_AGENT, | ||
}, | ||
}); | ||
if (mpSupportResponse.status >= 400 && mpSupportResponse.status < 600) { | ||
throw new Error(`Bad response ${mpSupportResponse.status}: ${mpSupportResponse.statusText}`); | ||
} | ||
|
||
return mpSupportResponse.json(); | ||
} | ||
|
||
interface SupportDetails { | ||
mpVersion: string; | ||
mpSpecs: string[]; | ||
javaSEVersions: string[]; | ||
} | ||
|
||
export async function getSupportedJavaAndSpecs( | ||
serverName: string, | ||
microprofileVersion: string | ||
): Promise<SupportDetails> { | ||
const serverSupportResponse = await fetch(`${MP_STARTER_API_ROOT}/supportMatrix/servers`, { | ||
method: "GET", | ||
headers: { | ||
"User-Agent": EXTENSION_USER_AGENT, | ||
}, | ||
}); | ||
if (serverSupportResponse.status >= 400 && serverSupportResponse.status < 600) { | ||
throw new Error( | ||
`Bad response ${serverSupportResponse.status}: ${serverSupportResponse.statusText}` | ||
); | ||
} | ||
|
||
const supportJSON = await serverSupportResponse.json(); | ||
const serverInformation = supportJSON.configs[serverName]; | ||
|
||
const supportDetails: SupportDetails | undefined = serverInformation.find( | ||
(supportRecord: SupportDetails) => supportRecord.mpVersion === microprofileVersion | ||
); | ||
|
||
if (supportDetails === undefined) { | ||
throw new Error("Unable to find supported MicroProfile specifications and Java versions"); | ||
} | ||
|
||
return supportDetails; | ||
} | ||
|
||
interface StarterProjectOptions { | ||
groupId: string; | ||
artifactId: string; | ||
mpVersion: string; | ||
supportedServer: string; | ||
javaSEVersion: string; | ||
selectedSpecs: string[]; | ||
} | ||
|
||
export async function downloadMPStarterProjectZip( | ||
options: StarterProjectOptions, | ||
downloadLocation: string | ||
): Promise<void> { | ||
const requestOptions = { | ||
url: `${MP_STARTER_API_ROOT}/project`, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"User-Agent": EXTENSION_USER_AGENT, | ||
}, | ||
body: JSON.stringify(options), | ||
}; | ||
|
||
await util.downloadFile(requestOptions, downloadLocation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters