in src/handler/AddStartersHandler.ts [30:111]
public async runSteps(_operationId: string, entry: vscode.Uri): Promise<void> {
const bootVersion: string = await searchForBootVersion(entry);
if (!bootVersion) {
const ex = new Error("Not a valid Spring Boot project.");
setUserError(ex);
throw ex;
}
const deps: string[] = []; // gid:aid
// Read pom.xml for $dependencies(gid, aid)
const content: string = vscode.window.activeTextEditor.document.getText();
const xml: { project: XmlNode } = await readXmlContent(content);
getDependencyNodes(xml.project).forEach(elem => {
deps.push(`${elem.groupId[0]}:${elem.artifactId[0]}`);
});
this.serviceUrl = await specifyServiceUrl();
if (this.serviceUrl === undefined) {
return;
}
// [interaction] Step: Dependencies, with pre-selected deps
const starters: IStarters = await vscode.window.withProgress<IStarters>(
{ location: vscode.ProgressLocation.Window },
async (p) => {
p.report({ message: `Fetching metadata for version ${bootVersion} ...` });
return await serviceManager.getStarters(this.serviceUrl, bootVersion);
},
);
const oldStarterIds: string[] = [];
if (!starters.dependencies) {
await vscode.window.showErrorMessage("Unable to retrieve information of available starters.");
return;
}
Object.keys(starters.dependencies).forEach(key => {
const elem: IMavenId = starters.dependencies[key];
if (deps.indexOf(`${elem.groupId}:${elem.artifactId}`) >= 0) {
oldStarterIds.push(key);
}
});
const dependencyManager = new DependencyManager();
dependencyManager.selectedIds = [].concat(oldStarterIds);
let current: IDependenciesItem = null;
do {
current = await vscode.window.showQuickPick(
dependencyManager.getQuickPickItems(this.serviceUrl, bootVersion),
{
ignoreFocusOut: true,
matchOnDescription: true,
matchOnDetail: true,
placeHolder: "Select dependencies to add.",
},
);
if (current && current.itemType === "dependency" && oldStarterIds.indexOf(current.id) === -1) {
dependencyManager.toggleDependency(current.id);
}
} while (current && current.itemType === "dependency");
if (!current) { return; }
// Diff deps for adding
const toAdd: string[] = dependencyManager.selectedIds.filter(elem => oldStarterIds.indexOf(elem) < 0);
if (toAdd.length === 0) {
vscode.window.showInformationMessage("No changes.");
return;
}
const msgAdd: string = (toAdd && toAdd.length) ? `Adding: [${toAdd.map(d => dependencyManager.dict[d] && dependencyManager.dict[d].name).filter(Boolean).join(", ")}].` : "";
const choice: string = await vscode.window.showWarningMessage(`${msgAdd} Proceed?`, "Proceed", "Cancel");
if (choice !== "Proceed") {
return;
}
const artifacts = toAdd.map(id => starters.dependencies[id]);
const bomIds = toAdd.map(id => starters.dependencies[id].bom).filter(Boolean);
const boms = bomIds.map(id => starters.boms[id]);
updatePom(entry, artifacts, boms);
vscode.window.showInformationMessage("Pom file successfully updated.");
return;
}