You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/12/01 23:52:34 UTC

[camel-karavan] branch main updated (bedabf6 -> 3c8a373)

This is an automated email from the ASF dual-hosted git repository.

marat pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


    from bedabf6  Support Code snippets in VSCode #514
     new d78a2b8  Fix issue with templates and code on new integration
     new 8a94b3e  Run with Maven
     new ff56c4e  Bump camel to 3.18.4
     new 3c8a373  Bump camel to 3.18.4

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 karavan-generator/pom.xml          |  4 +-
 karavan-vscode/package.json        | 12 +++---
 karavan-vscode/src/designerView.ts |  2 +-
 karavan-vscode/src/extension.ts    |  9 +++--
 karavan-vscode/src/jbang.ts        | 13 +++++--
 karavan-vscode/src/utils.ts        | 76 +++++++++++++++++++++-----------------
 karavan-vscode/webview/App.tsx     |  5 ++-
 7 files changed, 68 insertions(+), 53 deletions(-)


[camel-karavan] 03/04: Bump camel to 3.18.4

Posted by ma...@apache.org.
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 ff56c4ee2ca465f5e7ef3dada0c8fb929c3a758e
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Dec 1 18:52:10 2022 -0500

    Bump camel to 3.18.4
---
 karavan-vscode/package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index 3790296..c34627e 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -64,7 +64,7 @@
       "properties": {
         "camel.version": {
           "type": "string",
-          "default": "3.18.3",
+          "default": "3.18.4",
           "description": "Camel version",
           "scope": "machine",
           "order": 10


[camel-karavan] 02/04: Run with Maven

Posted by ma...@apache.org.
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 8a94b3e175b85063ae593573b0363e006b64f1d6
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Dec 1 18:47:52 2022 -0500

    Run with Maven
---
 karavan-vscode/package.json     | 10 +++++-----
 karavan-vscode/src/extension.ts |  9 +++++----
 karavan-vscode/src/jbang.ts     | 13 +++++++++----
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index 9f961cd..3790296 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -392,12 +392,12 @@
         },
         {
           "command": "karavan.open",
-          "when": "resourceExtname == .yaml",
+          "when": "resourceFilename =~ /.camel.yaml$/",
           "group": "karavan@4"
         },
         {
           "command": "karavan.jbang-run-file",
-          "when": "resourceExtname == .yaml",
+          "when": "resourceFilename =~ /.camel.yaml$/",
           "group": "karavan@5"
         },
         {
@@ -424,12 +424,12 @@
       "editor/title": [
         {
           "command": "karavan.open",
-          "when": "resourceExtname == .yaml",
+          "when": "resourceFilename =~ /.camel.yaml$/",
           "group": "navigation@1"
         },
         {
-          "command": "karavan.jbang-run-file",
-          "when": "resourceExtname == .yaml || karavan:loaded",
+          "command": "karavan.jbang-run-project",
+          "when": "resourceFilename =~ /.camel.yaml$/ || karavan:loaded",
           "group": "navigation@2"
         },
         {
diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index 99087b9..3eb4c11 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -115,7 +115,7 @@ export function activate(context: ExtensionContext) {
 
     // Run project
     const runProjectCommand = commands.registerCommand("karavan.jbang-run-project", (...args: any[]) => {
-        jbang.camelJbangRun();
+        exportProject(rootPath, true);
     });
     context.subscriptions.push(runProjectCommand);
 
@@ -148,11 +148,12 @@ export function activate(context: ExtensionContext) {
 /**
  * export into folder
  */
-export async function exportProject(rootPath?: string) {
+export async function exportProject(rootPath?: string, run?: boolean) {
     utils.getExportFolder()
         .then(folder => {
             if (folder){
-                jbang.camelJbangExport();
+                const fullPath = rootPath + path.sep + folder;
+                jbang.camelJbangExport(fullPath, run);
             } else {
                 window.showInputBox({
                     title: "Export project",
@@ -169,7 +170,7 @@ export async function exportProject(rootPath?: string) {
                 }).then(folder => {
                     if (folder && rootPath) {
                         const fullPath = rootPath + path.sep + folder;
-                        jbang.camelJbangExport(fullPath);
+                        jbang.camelJbangExport(fullPath, run);
                     }
                 });
             }
diff --git a/karavan-vscode/src/jbang.ts b/karavan-vscode/src/jbang.ts
index 456d46b..d90bbab 100644
--- a/karavan-vscode/src/jbang.ts
+++ b/karavan-vscode/src/jbang.ts
@@ -94,8 +94,13 @@ export function camelJbangRun(filename?: string) {
     terminal.sendText(command);
 }
 
-export function camelJbangExport(fullPath?: string) {
-    const command = createExportCommand(fullPath);
+export async function camelJbangExport(fullPath: string, run?: boolean) {
+    let command = createExportCommand(fullPath);
+    if (run) {
+        const runtime = await utils.getRuntime();
+        const mvn = runtime === 'quarkus' ? "quarkus:dev" : "spring-boot:run";
+        command = command.concat(" && mvn clean ").concat(mvn).concat(" -f ").concat(fullPath);
+    }
     const terminalId = "export";
     const existTerminal = TERMINALS.get(terminalId);
     if (existTerminal) existTerminal.dispose();
@@ -105,7 +110,7 @@ export function camelJbangExport(fullPath?: string) {
     terminal.sendText(command);
 }
 
-export function createExportCommand(fullPath?: string) {
+export function createExportCommand(fullPath: string) {
     const kameletsPath: string | undefined = workspace.getConfiguration().get("Karavan.kameletsPath");
     const cmd = "export --fresh " 
         + (fullPath ? " --directory=" + fullPath : '')
@@ -130,7 +135,7 @@ export function camelDeploy(directory: string) {
             window.showErrorMessage("Namespace not set \n" + val[3].error);
         }
         const deployCommand: string = workspace.getConfiguration().get("Karavan.".concat(runtime.replaceAll("-", "")).concat(utils.capitalize(target)).concat("Deploy")) || '';
-        const command = createExportCommand().concat(" && ").concat(deployCommand).concat(" -f ").concat(exportFolder);
+        const command = createExportCommand(directory).concat(" && ").concat(deployCommand).concat(" -f ").concat(exportFolder);
         camelRunDeploy(command, env);
     }).catch((reason: any) => {
         window.showErrorMessage("Error: \n" + reason.message);


[camel-karavan] 01/04: Fix issue with templates and code on new integration

Posted by ma...@apache.org.
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 d78a2b88110329b140c85ae37ac603ced5f75a3c
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Dec 1 18:03:29 2022 -0500

    Fix issue with templates and code on new integration
---
 karavan-vscode/src/designerView.ts |  2 +-
 karavan-vscode/src/utils.ts        | 76 +++++++++++++++++++++-----------------
 karavan-vscode/webview/App.tsx     |  5 ++-
 3 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/karavan-vscode/src/designerView.ts b/karavan-vscode/src/designerView.ts
index 8a4aa73..8aaf4fe 100644
--- a/karavan-vscode/src/designerView.ts
+++ b/karavan-vscode/src/designerView.ts
@@ -183,7 +183,7 @@ export class DesignerView {
             // Send templates
             panel.webview.postMessage({ command: 'templates', templates: Object.fromEntries(results[2]) });
             // Send java code
-            panel.webview.postMessage({ command: 'javaCode', templates: Object.fromEntries(results[3]) });
+            panel.webview.postMessage({ command: 'javaCode', javaCode: Object.fromEntries(results[3]) });
             // Send integration
             this.sendIntegrationData(panel, filename, relativePath, fullPath, reread, yaml, tab);
         }).catch(err => console.log(err));
diff --git a/karavan-vscode/src/utils.ts b/karavan-vscode/src/utils.ts
index dd5e22e..b02254d 100644
--- a/karavan-vscode/src/utils.ts
+++ b/karavan-vscode/src/utils.ts
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 import * as path from "path";
-import { workspace, Uri, window, ExtensionContext, FileType} from "vscode";
+import { workspace, Uri, window, ExtensionContext, FileType } from "vscode";
 import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
 
 export function getRoot(): string | undefined {
@@ -30,7 +30,7 @@ export function save(relativePath: string, text: string) {
     }
 }
 
-export function saveCode(name: string, yamlFullPath: string, yamFileName: string,  code: string) {
+export function saveCode(name: string, yamlFullPath: string, yamFileName: string, code: string) {
     if (workspace.workspaceFolders) {
         const folder = yamlFullPath.replace(yamFileName, '');
         write(path.join(folder, name + ".java"), code);
@@ -77,7 +77,7 @@ async function readFilesInDirByExtension(dir: string, extension: string): Promis
     const dirs: [string, FileType][] = await readDirectory(dir);
     for (let d in dirs) {
         const filename = dirs[d][0];
-        if (filename !== undefined && filename.endsWith(extension)){
+        if (filename !== undefined && filename.endsWith(extension)) {
             const file = await readFile(dir + "/" + filename);
             const code = Buffer.from(file).toString('utf8');
             result.set(filename, code);
@@ -100,9 +100,9 @@ export async function readTemplates(context: ExtensionContext) {
     const result = new Map<string, string>();
     const runtime = await getRuntime();
     const files = await readFilesInDirByExtension(path.join(context.extensionPath, 'snippets'), "java");
-    files.forEach((v, k)=>{
-        if (runtime && k.startsWith(runtime)){
-            const name = k.replace(runtime+"-", "").replace(".java", "");
+    files.forEach((v, k) => {
+        if (runtime && k.startsWith(runtime)) {
+            const name = k.replace(runtime + "-", "").replace(".java", "");
             result.set(name, v);
         }
     })
@@ -112,8 +112,8 @@ export async function readTemplates(context: ExtensionContext) {
 export async function readJavaCode(fullPath: string) {
     const result = new Map<string, string>();
     const codePath = path.dirname(fullPath);
-    const javaFiles = await getJavaFiles(codePath); 
-    for (let x in javaFiles){
+    const javaFiles = await getJavaFiles(codePath);
+    for (let x in javaFiles) {
         const fname = javaFiles[x];
         const readData = await readFile(fname);
         const code = Buffer.from(readData).toString('utf8');
@@ -146,7 +146,7 @@ export async function getAllFiles(dirPath, arrayOfFiles: string[]) {
 
     arrayOfFiles = arrayOfFiles || [];
 
-    for (let x in files){
+    for (let x in files) {
         const filename = files[x][0];
         const type = files[x][1];
         if (type === FileType.Directory) {
@@ -197,11 +197,11 @@ export async function getJsonFiles(baseDir: string) {
 export async function getIntegrationFiles(baseDir: string) {
     const result: string[] = []
     const files = await getYamlFiles(baseDir);
-    for (let x in files){
+    for (let x in files) {
         const filename = files[x];
         const readData = await readFile(path.resolve(filename));
         const yaml = Buffer.from(readData).toString('utf8');
-        if (!filename.startsWith(baseDir + path.sep + "target") && CamelDefinitionYaml.yamlIsIntegration(yaml)){
+        if (!filename.startsWith(baseDir + path.sep + "target") && CamelDefinitionYaml.yamlIsIntegration(yaml)) {
             result.push(yaml);
         }
     }
@@ -210,21 +210,26 @@ export async function getIntegrationFiles(baseDir: string) {
 
 
 export async function getProperties(rootPath?: string) {
-    if (rootPath === undefined)
-        rootPath = (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0)) ? workspace.workspaceFolders[0].uri.fsPath : undefined;
-    if (rootPath) {
-        const readData = await readFile(path.resolve(rootPath, "application.properties"));
-        return Buffer.from(readData).toString('utf8');
-    } else {
-        const readData = await readFile(path.resolve("application.properties"));
-        return Buffer.from(readData).toString('utf8');
+    try {
+        if (rootPath === undefined)
+            rootPath = (workspace.workspaceFolders && (workspace.workspaceFolders.length > 0)) ? workspace.workspaceFolders[0].uri.fsPath : undefined;
+        if (rootPath) {
+            const readData = await readFile(path.resolve(rootPath, "application.properties"));
+            return Buffer.from(readData).toString('utf8');
+
+        } else {
+            const readData = await readFile(path.resolve("application.properties"));
+            return Buffer.from(readData).toString('utf8');
+        }
+    } catch (err) {
+        return '';
     }
 }
 
 export async function getProperty(name: string) {
     const properties = await getProperties();
     const props = properties.split("\n");
-    for (var p of props){
+    for (var p of props) {
         const pair = p.split("=");
         if (pair[0] === name) {
             return pair[1];
@@ -233,8 +238,11 @@ export async function getProperty(name: string) {
 }
 
 export async function getRuntime() {
-    return getProperty("camel.jbang.runtime");
-;}
+    const defaultRuntime: string = workspace.getConfiguration().get("camel.runtimes") || "";
+    const runtime = await getProperty("camel.jbang.runtime");
+    const result:string = runtime !== undefined ? runtime : defaultRuntime;
+    return result;
+}
 
 export async function getTarget() {
     return getProperty('camel.karavan.target');
@@ -246,7 +254,7 @@ export async function getExportFolder() {
 
 export async function stat(fullPath: string) {
     const uriFile: Uri = Uri.file(fullPath);
-    return  workspace.fs.stat(uriFile);
+    return workspace.fs.stat(uriFile);
 }
 
 export async function readDirectory(fullPath: string) {
@@ -262,38 +270,38 @@ export async function readFile(fullPath: string) {
 export async function write(fullPath: string, code: string) {
     const uriFile: Uri = Uri.file(fullPath);
     workspace.fs.writeFile(uriFile, Buffer.from(code, 'utf8'))
-    .then(
-        value => {}, 
-        reason => window.showErrorMessage("Error: " + reason) 
-    );
+        .then(
+            value => { },
+            reason => window.showErrorMessage("Error: " + reason)
+        );
 }
 
-export function capitalize (text) {
+export function capitalize(text) {
     return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
 }
 
-export function defaultGAV (): string | undefined {
+export function defaultGAV(): string | undefined {
     const groupId = workspace.getConfiguration().get("Karavan.defaultGroupId");
     const artifact = currentFolderName();
     return groupId + ":" + artifact + ":1";
 }
 
-export function currentFolderName (): string | undefined {
+export function currentFolderName(): string | undefined {
     if (workspace.workspaceFolders) {
         const uriFolder: Uri = workspace.workspaceFolders[0].uri;
         const parts = uriFolder.fsPath.split(path.sep);
-        const name = parts.at(parts.length -1) || '';
+        const name = parts.at(parts.length - 1) || '';
         return name;
     }
 }
 
-export async function createApplicationproperties(runtime: string, gav: string, target: string ) {
+export async function createApplicationproperties(runtime: string, gav: string, target: string) {
     if (workspace.workspaceFolders) {
         const uriFolder: Uri = workspace.workspaceFolders[0].uri;
         const name = currentFolderName() || "";
 
-        const props: string [] = workspace.getConfiguration().get("Karavan.applicationProperties") || [];
-        const runtimeProps: string [] = workspace.getConfiguration().get("Karavan.".concat(runtime.replaceAll("-", "")).concat(capitalize(target)).concat("Properties")) || [];
+        const props: string[] = workspace.getConfiguration().get("Karavan.applicationProperties") || [];
+        const runtimeProps: string[] = workspace.getConfiguration().get("Karavan.".concat(runtime.replaceAll("-", "")).concat(capitalize(target)).concat("Properties")) || [];
 
         const text = props.concat(runtimeProps).map(v => {
             if (v.includes('$NAME')) return v.replace('$NAME', name)
diff --git a/karavan-vscode/webview/App.tsx b/karavan-vscode/webview/App.tsx
index f6f1925..60fc68c 100644
--- a/karavan-vscode/webview/App.tsx
+++ b/karavan-vscode/webview/App.tsx
@@ -99,7 +99,7 @@ class App extends React.Component<Props, State> {
         TemplateApi.saveTemplates(map, true);
         break;  
       case 'javaCode':
-        const javaCode = message.templates;
+        const javaCode = message.javaCode;
         const javaCodeMap = new Map( Object.keys(javaCode).map(key => [key, javaCode[key]]));
         TemplateApi.saveJavaCodes(javaCodeMap, true);
         break;  
@@ -169,7 +169,8 @@ class App extends React.Component<Props, State> {
             dark={this.props.dark} 
             onSaveCustomCode={(name, code) => this.saveJavCode(name, code)}
             onGetCustomCode={(name, javaType) => {
-                const code = TemplateApi.getJavaCode(name);
+                let code = TemplateApi.getJavaCode(name);
+                if (code === undefined || code.length === 0) code = TemplateApi.generateCode(name, javaType);
                 return new Promise<string | undefined>(resolve => resolve(code))
             }}
             />


[camel-karavan] 04/04: Bump camel to 3.18.4

Posted by ma...@apache.org.
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 3c8a373ec1f6d3a1deeb5c1c034fc132c41d9885
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Dec 1 18:52:18 2022 -0500

    Bump camel to 3.18.4
---
 karavan-generator/pom.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/karavan-generator/pom.xml b/karavan-generator/pom.xml
index dca60de..0ec37a4 100644
--- a/karavan-generator/pom.xml
+++ b/karavan-generator/pom.xml
@@ -29,9 +29,9 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
         <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
-        <quarkus.platform.version>2.13.2.Final</quarkus.platform.version>
+        <quarkus.platform.version>2.14.0.Final</quarkus.platform.version>
         <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
-        <version.camel-core>3.18.3</version.camel-core>
+        <version.camel-core>3.18.4</version.camel-core>
         <version.camel-kamelet>0.9.3</version.camel-kamelet>
     </properties>
     <dependencyManagement>