This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit d4f73bfb8668fae1f5acaf1d826bca02525818e1 Author: Marat Gubaidullin <ma...@talismancloud.io> AuthorDate: Thu Feb 1 17:36:52 2024 -0500 Vscode #1094 --- karavan-vscode/src/designerView.ts | 16 +++++++++---- karavan-vscode/src/utils.ts | 48 +++++++++++++++++++++++++++++++------- karavan-vscode/webview/App.tsx | 11 ++++++--- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/karavan-vscode/src/designerView.ts b/karavan-vscode/src/designerView.ts index 2b4da788..0e9ecc20 100644 --- a/karavan-vscode/src/designerView.ts +++ b/karavan-vscode/src/designerView.ts @@ -20,6 +20,7 @@ import * as utils from "./utils"; import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml"; import { Integration, KameletTypes, Metadata, MetadataLabels } from "core/model/IntegrationDefinition"; import { getWebviewContent } from "./webviewContent"; +import { RegistryBeanDefinition } from "core/model/CamelDefinition"; const KARAVAN_LOADED = "karavan:loaded"; const KARAVAN_PANELS: Map<string, WebviewPanel> = new Map<string, WebviewPanel>(); @@ -182,7 +183,9 @@ export class DesignerView { utils.readSupportedComponents(), utils.readSupportedOnlySettings(), // Read property placeholders - utils.readPropertyPlaceholder(this.context) + utils.readPropertyPlaceholders(this.context), + // Read beans + utils.readBeans(fullPath) ]).then(results => { // Send Kamelets panel.webview.postMessage({ command: 'kamelets', kamelets: results[0] }); @@ -196,24 +199,27 @@ export class DesignerView { if (results[4]) panel.webview.postMessage({ command: 'supportedComponents', components: results[4]}); if (results[5] === true) panel.webview.postMessage({ command: 'supportedOnly'}); // Send integration - this.sendIntegrationData(panel, filename, relativePath, fullPath, reread, yaml, tab, results[6]); + this.sendIntegrationData(panel, filename, relativePath, fullPath, reread, yaml, tab, results[6], results[7]); }).catch(err => console.log(err)); } - sendIntegrationData(panel: WebviewPanel, filename: string, relativePath: string, fullPath: string, reread: boolean, yaml?: string, tab?: string, propertyPlaceholders?: string[]) { + sendIntegrationData(panel: WebviewPanel, filename: string, relativePath: string, + fullPath: string, reread: boolean, yaml?: string, tab?: string, propertyPlaceholders?: string[], beans?: RegistryBeanDefinition[]) { // Read file if required if (reread) { utils.readFile(path.resolve(fullPath)).then(readData => { const yaml = Buffer.from(readData).toString('utf8'); // Send integration panel.webview.postMessage( - { command: 'open', page: "designer", filename: filename, relativePath: relativePath, fullPath:fullPath, yaml: yaml, tab: tab, propertyPlaceholders: propertyPlaceholders }); + { command: 'open', page: "designer", filename: filename, relativePath: relativePath, + fullPath:fullPath, yaml: yaml, tab: tab, propertyPlaceholders: propertyPlaceholders, beans: beans }); }); } else { // Send integration panel.webview.postMessage( - { command: 'open', page: "designer", filename: filename, relativePath: relativePath, fullPath:fullPath, yaml: yaml, tab: tab, propertyPlaceholders: propertyPlaceholders }); + { command: 'open', page: "designer", filename: filename, relativePath: relativePath, + fullPath:fullPath, yaml: yaml, tab: tab, propertyPlaceholders: propertyPlaceholders, beans: beans }); } } diff --git a/karavan-vscode/src/utils.ts b/karavan-vscode/src/utils.ts index 8462cbc4..2d94d2a6 100644 --- a/karavan-vscode/src/utils.ts +++ b/karavan-vscode/src/utils.ts @@ -17,7 +17,8 @@ import * as path from "path"; import { workspace, Uri, window, ExtensionContext, FileType } from "vscode"; import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml"; -import { KameletTypes } from "webview/core/model/IntegrationDefinition"; +import { Integration, KameletTypes } from "core/model/IntegrationDefinition"; +import { RegistryBeanDefinition } from "core/model/CamelDefinition"; export function getRoot(): string | undefined { return (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0)) @@ -120,14 +121,14 @@ export async function readComponents(context: ExtensionContext) { return jsons; } -export async function readPropertyPlaceholder(context: ExtensionContext) { +export async function readPropertyPlaceholders(context: ExtensionContext) { const result: string[] = []; const properties = await getProperties(); const lines = properties.split('\n').map((line) => line.trim()); - lines - .filter(line => !line.startsWith("camel.") && !line.startsWith("jkube.") && !line.startsWith("jib.")) - .filter(line => line !== undefined && line !== null && line.length > 0) - .forEach(line => { + lines + .filter(line => !line.startsWith("camel.") && !line.startsWith("jkube.") && !line.startsWith("jib.")) + .filter(line => line !== undefined && line !== null && line.length > 0) + .forEach(line => { const parts = line.split("="); if (parts.length > 0) { result.push(parts[0]); @@ -136,6 +137,35 @@ export async function readPropertyPlaceholder(context: ExtensionContext) { return result; } +function getBeans (integration: Integration): RegistryBeanDefinition[] { + const result: RegistryBeanDefinition[] = []; + const beans = integration.spec.flows?.filter((e: any) => e.dslName === 'Beans'); + if (beans && beans.length > 0 && beans[0].beans) { + result.push(...beans[0].beans); + } + return result; +} + +export async function readBeans(fullPath: string) { + const result: RegistryBeanDefinition[] = []; + try { + const codePath = path.dirname(fullPath); + const files = await getCamelYamlFiles(codePath); + for (let x in files) { + const filename = files[x]; + const readData = await readFile(filename); + const code = Buffer.from(readData).toString('utf8'); + const i = CamelDefinitionYaml.yamlToIntegration(filename, code); + const beans = getBeans(i); + result.push(...beans); + } + } + catch (e) { + console.log((e as Error).message); + } + return result; +} + export async function readTemplates(context: ExtensionContext) { const result = new Map<string, string>(); const runtime = await getRuntime(); @@ -235,11 +265,11 @@ export async function readCamelYamlFiles(dir: string) { const result: any = {}; const files = await getCamelYamlFiles(dir); const camelFiles = exportFolder ? files.filter(f => !f.startsWith(fullExportFolder)) : files; - for (let x in camelFiles){ + for (let x in camelFiles) { const filename = camelFiles[x]; const readData = await readFile(path.resolve(filename)); const yaml = Buffer.from(readData).toString('utf8'); - if (CamelDefinitionYaml.yamlIsIntegration(yaml)){ + if (CamelDefinitionYaml.yamlIsIntegration(yaml)) { const basename = filename.replace(dir, ''); result[basename] = yaml; } @@ -306,7 +336,7 @@ export async function getProperty(name: string) { export async function getRuntime() { const defaultRuntime: string = workspace.getConfiguration().get("camel.runtimes") || ""; const runtime = await getProperty("camel.jbang.runtime"); - const result:string = runtime !== undefined ? runtime : defaultRuntime; + const result: string = runtime !== undefined ? runtime : defaultRuntime; return result; } diff --git a/karavan-vscode/webview/App.tsx b/karavan-vscode/webview/App.tsx index 7611f8fb..8addc851 100644 --- a/karavan-vscode/webview/App.tsx +++ b/karavan-vscode/webview/App.tsx @@ -27,6 +27,7 @@ import { EventBus } from "./designer/utils/EventBus"; import { KnowledgebasePage } from "./knowledgebase/KnowledgebasePage"; import { TopologyTab } from "./topology/TopologyTab"; import { IntegrationFile } from "./topology/TopologyStore"; +import {RegistryBeanDefinition} from "core/model/CamelDefinition"; interface Props { dark: boolean @@ -47,7 +48,8 @@ interface State { active: boolean tab?: "routes" | "rest" | "beans" files: IntegrationFile[], - propertyPlaceholders: string[] + propertyPlaceholders: string[], + beans: RegistryBeanDefinition[] } class App extends React.Component<Props, State> { @@ -65,7 +67,8 @@ class App extends React.Component<Props, State> { page: "designer", active: false, files: [], - propertyPlaceholders: [] + propertyPlaceholders: [], + beans: [] }; saveScheduledChanges = () => { @@ -156,7 +159,8 @@ class App extends React.Component<Props, State> { loaded: true, active: true, tab: message.tab, - propertyPlaceholders: message.propertyPlaceholders + propertyPlaceholders: message.propertyPlaceholders, + beans: message.beans }); } break; @@ -228,6 +232,7 @@ class App extends React.Component<Props, State> { }} propertyPlaceholders={this.state.propertyPlaceholders} onSavePropertyPlaceholder={(key, value) => this.savePropertyPlaceholder(key, value)} + beans={this.state.beans} /> } {loaded && page === "knowledgebase" && <KnowledgebasePage dark={dark} />}