From c9185976a5c9645cd8cd03a405fcb651ac818e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Wed, 18 Nov 2020 14:58:19 +0100 Subject: [PATCH 01/10] command cobiGenJava for katacoda runner --- playbooks/cobigen-cli/index.asciidoc | 6 ++++++ runners/katacoda/index.ts | 19 ++++++++++++++++++ runners/katacoda/templates/cobiGenJava.md | 14 +++++++++++++ .../templates/files/cobigen-0.0.1.vsix | Bin 0 -> 2916 bytes .../templates/scripts/installCobiGenPlugin.sh | 6 ++++++ 5 files changed, 45 insertions(+) create mode 100644 runners/katacoda/templates/cobiGenJava.md create mode 100644 runners/katacoda/templates/files/cobigen-0.0.1.vsix create mode 100644 runners/katacoda/templates/scripts/installCobiGenPlugin.sh diff --git a/playbooks/cobigen-cli/index.asciidoc b/playbooks/cobigen-cli/index.asciidoc index b30e8e16..765951d2 100644 --- a/playbooks/cobigen-cli/index.asciidoc +++ b/playbooks/cobigen-cli/index.asciidoc @@ -18,3 +18,9 @@ Now, you have to download cobigen -- installCobiGen() -- + +The CobiGen plugin for VS Code is already installed. You can use it right away. +[step] +-- +cobiGenJava(devonfw/workspaces/main/Test.java,[1 2 3 4]) +-- \ No newline at end of file diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index e4f71979..52d75e96 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -94,6 +94,25 @@ export class Katacoda extends Runner { return null; } + runCobiGenJava(step: Step, command: Command): RunResult { + let params = command.parameters.split(","); + let cobiGenTemplates = params[1].replace(/\[/, "").replace("\]", "").replace(/ /g, ","); + + this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" }); + this.setupScripts.push({ + "name": "Install CobiGen plugin", + "script": "installCobiGenPlugin.sh" + }); + this.assetManager.registerFile(path.join(this.getRunnerDirectory(), "templates", "files", "cobigen-0.0.1.vsix"), "setup/cobigen-0.0.1.vsix", "/root/setup", true) + + this.steps.push({ + "title": "CobiGen Java", + "text": "step" + this.stepsCount + ".md" + }); + this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates }); + return null; + } + private renderTemplate(name: string, targetPath: string, variables) { let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8'); let result = ejs.render(template, variables); diff --git a/runners/katacoda/templates/cobiGenJava.md b/runners/katacoda/templates/cobiGenJava.md new file mode 100644 index 00000000..99bae07f --- /dev/null +++ b/runners/katacoda/templates/cobiGenJava.md @@ -0,0 +1,14 @@ +<%= text; %> + +## CobiGen Java + +Open the following java file in the IDE. +`<%= javaFile; %>`{{open}} + +You can use the plugin simply via the context menu. Make a right click on the java file (in the explorer on the left or in the editor itself). The context menu will open and you can start the CobiGen Plugin by clicking on 'CobiGen'. + +A terminal will open on the bottom of the IDE and CobiGen CLI will start. + +You can choose the templates CobiGen should use by entering the numbers. + +`<%= cobiGenTemplates; %>`{{execute}} \ No newline at end of file diff --git a/runners/katacoda/templates/files/cobigen-0.0.1.vsix b/runners/katacoda/templates/files/cobigen-0.0.1.vsix new file mode 100644 index 0000000000000000000000000000000000000000..ed7c924ef5e7c51dbcb95b09e810218f102afa45 GIT binary patch literal 2916 zcmZ{mc{r4N8^^~IMq^**3}s)&I)ikqWy}m?A2A&vvK{-_2GbeNgocm^Clz84p~;eC z-;ZR;Qnn+E>{RMxNja8xdf%7Q`=0x`p6mJj{`p?deO;gX`@OMdEUbb600##^)H~QZ zF2iN)3^M?LV*>z$0RVspk>G(3@eaVNhJ|<&{ax_hKYN4_XgG`HmvG*ub)~$?3YQ5a z#qj(otguj+HI?+xeO9toCd^$oVq+{kH6_KP!2v}wnZ3EBKajZ;A5O-&da}Rdko_B< zL2zVue^8rZJ>B=Vez&`6%YmLnaS(31Zc@SKmc67ncZ0BY0(G8Zfwc2_<88qGdsg4pN?bRv8i13uO1E z=H@Fcb3KPA?S2MZ7YlH~P2nrRAgH;><2h-w zRvtJR^di6SmAB|^Y~rw#kCXF2fih~%HioH*rKTs;i2b;_ym5L+KhUFFYK~Mz{O#tI z3)j+xFYU-DvTt}vpTk2QYq3S{@Go6J%TkS}*Y#^wYffqtluu=j zSX>sCbNkT#vm=xr%Iz*AEy=Xt9u)gzZ#gx2KIYA!Xo?~(HYK`4E|!=p@@ZNkW1BLmvO|1-wshM%A(Ne=FI(iKlh``1&>Sx+XDz5v zwi>WWS|^yE;REe#vkSeoS-P$AvGXR1q;76HkH`Nr+(=J>w(0c=C2HW^6xR+H+6iw*GrC>-sZv{A7cE5*L-<=Z}%Bqh?wth9!}EiQ02Z?)K4c&HjN{lf6tkY?+}EUc@C7U zoHUrc!)$s|AjrD&Hj9t;IxBEWNIp7ps4+V6VMqOt${!zpQ(I+EB4&o9y8+R0~PuZwd$w>Vmdbg!M=K+r&HPuGq|Rz zidyq9b9N36!Lr(xc5BnRdnMVYSE;dA^zLq5HeNH&>yiHSstWXcHR59x2@R=jw-t5N zb;vs|AN%x0{VOnUQ)4cf_8$r~5ngkWgNrquwMEb%W|6XRov|5K@iCrt$iinpc0xHf+4iMm zVm&6Ez%4l>#tFKEGf+}kJ0Ua-5z!j&;kx8|cZzB{V!B^3JsM^Z9&M{zBDKssak~mF zY3@rgPRI3{Dj^LGLBEV<-RuH3_IVmuk%gMJ5eS8>+>+-AYrYm<#Lr;1;?68TkVnsZ z*W{fMhoQD$P;M2B25x9<`tZ?+2-}>TaU!`+hcgMAH4KqXW&OJRpqa=760n=%+T^lJ z*52eOv8q2NZMAEE_3cOX#6ikwDRG*we>$y>fZ4EU=}V2r4+iFpZ@VsqPkX+$dn|ui z!w$LCSqL;~pID4Ag=vM33ij=xf)u%v(@zG}1TlvPrkM{+>HV}@mU7}&T}s!jiPc~$ zjmOsug|f;{f|FiimC7+QQT7G}_t&WzE|CyBFW5rQ5jMLXLI>#sAwp;|E1X927k zJBN#rK)wtkm8w|*fUm6WdL3o$=pY5UxcRzxdN3#p!2fPjfoE`*eZNfNlzSyq0eE-R zChFAksOoqETW)dbGeaq0YA`?R-j@(ZsU@PcTD?Daj>2i#gsX@^bd~cz$_DvbqkB_=jHkHmJnY z`REvLicR4f6C9_WIZ1cR5X!dB|Ck`mZMt_E^lKYjC$Bs0-EUDmHStYX_s%|3oP3kmxsR zlMabED-H^Hv+i|6cit&T4h)t-w8<`es>#U*Y3tikUyG4FhRNXwDJ??i)jda61a2 zXTv_c(|62|TrYIeaQje_1GK6nC;X|iF*$fHP|^5gyt__zm{0Q{lq&ajV*f}%;Wr6;;<2G=&!$Ih+2#R$z z2=|$l^_W^KR;v?pF=ONtFiDojqrz^L^L|yVCY2DCckZcZ zoBFZS3IybU~dyVh2_^U=RWBUG2GJh}deXe~K@MQVsCyu1t zfyP06d^_x4;^UyIqfm_TKWyZG!sJ_>FV^ra2w$w>psJ(F8O!Zgoo|ieK;xf~Inbzz cn&kLa;}9UM*)fJV0Kmq0ZZSBk1%A2x3*;Qc?*IS* literal 0 HcmV?d00001 diff --git a/runners/katacoda/templates/scripts/installCobiGenPlugin.sh b/runners/katacoda/templates/scripts/installCobiGenPlugin.sh new file mode 100644 index 00000000..3fb5eae6 --- /dev/null +++ b/runners/katacoda/templates/scripts/installCobiGenPlugin.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +apt install libarchive-tools -y +cd /root/setup/ +bsdtar -xvf <%= vsixFile; %> - extension +mv extension /opt/.katacodacode/extensions/<%= pluginName; %> From 5048a6b1271117655326363ffc024133c9ef7e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Wed, 18 Nov 2020 15:18:58 +0100 Subject: [PATCH 02/10] command cobiGenJava for katacoda runner --- playbooks/cobigen-cli/index.asciidoc | 2 +- runners/katacoda/templates/cobiGenJava.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/playbooks/cobigen-cli/index.asciidoc b/playbooks/cobigen-cli/index.asciidoc index 765951d2..9afb30c6 100644 --- a/playbooks/cobigen-cli/index.asciidoc +++ b/playbooks/cobigen-cli/index.asciidoc @@ -22,5 +22,5 @@ installCobiGen() The CobiGen plugin for VS Code is already installed. You can use it right away. [step] -- -cobiGenJava(devonfw/workspaces/main/Test.java,[1 2 3 4]) +cobiGenJava(Test.java,[1 2 3 4]) -- \ No newline at end of file diff --git a/runners/katacoda/templates/cobiGenJava.md b/runners/katacoda/templates/cobiGenJava.md index 99bae07f..bde3fac7 100644 --- a/runners/katacoda/templates/cobiGenJava.md +++ b/runners/katacoda/templates/cobiGenJava.md @@ -3,7 +3,7 @@ ## CobiGen Java Open the following java file in the IDE. -`<%= javaFile; %>`{{open}} +`devonfw/workspaces/main/<%= javaFile; %>`{{open}} You can use the plugin simply via the context menu. Make a right click on the java file (in the explorer on the left or in the editor itself). The context menu will open and you can start the CobiGen Plugin by clicking on 'CobiGen'. From bac976b55af97073151cdc8325b7f91e44a0ffda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Wed, 18 Nov 2020 19:14:40 +0100 Subject: [PATCH 03/10] improved katacoda runner for parsing input parameter --- engine/runner.ts | 9 +++++++++ playbooks/cobigen-cli/index.asciidoc | 8 +++++--- runners/katacoda/index.ts | 9 +++++---- runners/katacoda/templates/cobiGenJava.md | 4 +++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/engine/runner.ts b/engine/runner.ts index b43118e4..86fd2355 100644 --- a/engine/runner.ts +++ b/engine/runner.ts @@ -109,4 +109,13 @@ export abstract class Runner { fs.mkdirSync(path, { recursive: true }); return path; } + + protected parseInputParameters(parameterString: string) { + let regex = /(((?\[[^\]]+\])|(?[^[,]+))\s*,?\s*)/mg; + let parameters = []; + for (let matches = regex.exec(parameterString); matches != null; matches = regex.exec(parameterString)) { + parameters.push(matches[2]); + } + return parameters; + } } \ No newline at end of file diff --git a/playbooks/cobigen-cli/index.asciidoc b/playbooks/cobigen-cli/index.asciidoc index 9afb30c6..7f95317f 100644 --- a/playbooks/cobigen-cli/index.asciidoc +++ b/playbooks/cobigen-cli/index.asciidoc @@ -19,8 +19,10 @@ Now, you have to download cobigen installCobiGen() -- -The CobiGen plugin for VS Code is already installed. You can use it right away. +==== +The CobiGen plugin for VS Code is already installed. We will use it to generate code from one single java class based on existing templates. [step] -- -cobiGenJava(Test.java,[1 2 3 4]) --- \ No newline at end of file +cobiGenJava(Test.java,[1,2,3,4]) +-- +==== \ No newline at end of file diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 52d75e96..4573d844 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -66,10 +66,11 @@ export class Katacoda extends Runner { } runInstallDevonfwIde(step: Step, command: Command): RunResult { - let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").replace(/vscode/,"").replace(/eclipse/, "").trim(); + let params = this.parseInputParameters(command.parameters); + let tools = params[0].replace(/\[/, "").replace(/\]/g, "").replace(/,/, " ").replace(/vscode/,"").replace(/eclipse/, "").trim(); // create script to download devonfw ide settings - this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: params, cloneDir: "/root/devonfw-settings/"}); + this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: tools, cloneDir: "/root/devonfw-settings/"}); // add the script to the setup scripts for executing it at the beginning of the tutorial this.setupScripts.push({ @@ -95,8 +96,8 @@ export class Katacoda extends Runner { } runCobiGenJava(step: Step, command: Command): RunResult { - let params = command.parameters.split(","); - let cobiGenTemplates = params[1].replace(/\[/, "").replace("\]", "").replace(/ /g, ","); + let params = this.parseInputParameters(command.parameters) + let cobiGenTemplates = params[1].replace(/\[/, "").replace(/\]/g, ""); this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" }); this.setupScripts.push({ diff --git a/runners/katacoda/templates/cobiGenJava.md b/runners/katacoda/templates/cobiGenJava.md index bde3fac7..1ed1c905 100644 --- a/runners/katacoda/templates/cobiGenJava.md +++ b/runners/katacoda/templates/cobiGenJava.md @@ -11,4 +11,6 @@ A terminal will open on the bottom of the IDE and CobiGen CLI will start. You can choose the templates CobiGen should use by entering the numbers. -`<%= cobiGenTemplates; %>`{{execute}} \ No newline at end of file +`<%= cobiGenTemplates; %>`{{execute}} + +<%= textAfter; %> \ No newline at end of file From 2c17edf89c3e74ae341404e41385ab9579964e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Thu, 19 Nov 2020 13:24:50 +0100 Subject: [PATCH 04/10] changed parameter handling in commands --- engine/command.ts | 7 ++++++- engine/parser.def | 2 +- engine/parser.ts | 2 +- engine/runner.ts | 9 --------- playbooks/cobigen-cli/index.asciidoc | 8 ++++---- runners/console/index.ts | 6 +++--- runners/katacoda/index.ts | 7 +++---- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/engine/command.ts b/engine/command.ts index 6cb32bfe..ce3aa198 100644 --- a/engine/command.ts +++ b/engine/command.ts @@ -1,4 +1,9 @@ export class Command{ public name: string; - public parameters: string; + public parameterString: string; + + get parameters(): any[] { + let params = JSON.parse("[" + this.parameterString + "]"); + return params; + } } \ No newline at end of file diff --git a/engine/parser.def b/engine/parser.def index cd9a360b..7d9e9cc6 100644 --- a/engine/parser.def +++ b/engine/parser.def @@ -52,7 +52,7 @@ stepline = !"--" string __ { return { "stepline": text()}; } string "string" - = [a-zA-Z0-9.(),;:/-_- ]+ { return text(); } + = [a-zA-Z0-9.(),;:/-_-" ]+ { return text(); } _ "whitespace" = [ \t]* diff --git a/engine/parser.ts b/engine/parser.ts index b8f227e3..2208d658 100644 --- a/engine/parser.ts +++ b/engine/parser.ts @@ -54,7 +54,7 @@ export class Parser { let result = re.exec(line); let retVal = new Command(); retVal.name = result[1].trim(); - retVal.parameters = result[2]; + retVal.parameterString = result[2]; return retVal; } diff --git a/engine/runner.ts b/engine/runner.ts index 86fd2355..b43118e4 100644 --- a/engine/runner.ts +++ b/engine/runner.ts @@ -109,13 +109,4 @@ export abstract class Runner { fs.mkdirSync(path, { recursive: true }); return path; } - - protected parseInputParameters(parameterString: string) { - let regex = /(((?\[[^\]]+\])|(?[^[,]+))\s*,?\s*)/mg; - let parameters = []; - for (let matches = regex.exec(parameterString); matches != null; matches = regex.exec(parameterString)) { - parameters.push(matches[2]); - } - return parameters; - } } \ No newline at end of file diff --git a/playbooks/cobigen-cli/index.asciidoc b/playbooks/cobigen-cli/index.asciidoc index 7f95317f..48cdddcf 100644 --- a/playbooks/cobigen-cli/index.asciidoc +++ b/playbooks/cobigen-cli/index.asciidoc @@ -10,7 +10,7 @@ More information about CobiGen on https://devonfw.com/website/pages/docs/master- To use the cobigen cli you first have to install the devonfw ide. You will find more information about devonfw on https://devonfw.com/website/pages/welcome/welcome.html. [step] -- -installDevonfwIde([java,mvn]) +installDevonfwIde(["java","mvn"]) -- Now, you have to download cobigen @@ -20,9 +20,9 @@ installCobiGen() -- ==== -The CobiGen plugin for VS Code is already installed. We will use it to generate code from one single java class based on existing templates. +CobiGen is integrated via plugin in the VS Code IDE. We will use it to generate code from one single java class based on existing templates. [step] -- -cobiGenJava(Test.java,[1,2,3,4]) +cobiGenJava("Test.java",[1,2,3,4]) -- -==== \ No newline at end of file +==== diff --git a/runners/console/index.ts b/runners/console/index.ts index d6dcff4e..57cc2201 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -16,8 +16,7 @@ export class Console extends Runner { let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true); this.executeCommandSync("git clone https://github.com/devonfw/ide-settings.git settings", settingsDir, result); - let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").trim(); - let tools = "DEVON_IDE_TOOLS=(" + params + ")"; + let tools = "DEVON_IDE_TOOLS=(" + command.parameters[0].join(" ") + ")"; fs.writeFileSync(path.join(settingsDir, "settings", "devon.properties"), tools); fs.renameSync(path.join(settingsDir, "settings"), path.join(settingsDir, "settings.git")); this.executeCommandSync("git add -A && git config user.email \"devonfw\" && git config user.name \"devonfw\" && git commit -m \"devonfw\"", path.join(settingsDir, "settings.git"), result); @@ -37,7 +36,7 @@ export class Console extends Runner { } async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { - let installedTools = command.parameters.replace(/\[/, "").replace("\]", "").replace(/mvn/, "maven").split(","); + let installedTools = command.parameters[0]; let assert = new Assertions() .noErrorCode(result) @@ -46,6 +45,7 @@ export class Console extends Runner { .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main")); for(let i = 0; i < installedTools.length; i++) { + if(installedTools[i] == "mvn") installedTools[i] = "maven"; assert.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", installedTools[i])); } } diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 4573d844..50353b5c 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -66,8 +66,7 @@ export class Katacoda extends Runner { } runInstallDevonfwIde(step: Step, command: Command): RunResult { - let params = this.parseInputParameters(command.parameters); - let tools = params[0].replace(/\[/, "").replace(/\]/g, "").replace(/,/, " ").replace(/vscode/,"").replace(/eclipse/, "").trim(); + let tools = command.parameters[0].join(" ").replace(/vscode/,"").replace(/eclipse/, "").trim(); // create script to download devonfw ide settings this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: tools, cloneDir: "/root/devonfw-settings/"}); @@ -96,8 +95,8 @@ export class Katacoda extends Runner { } runCobiGenJava(step: Step, command: Command): RunResult { - let params = this.parseInputParameters(command.parameters) - let cobiGenTemplates = params[1].replace(/\[/, "").replace(/\]/g, ""); + let params = command.parameters; + let cobiGenTemplates = params[1].join(","); this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" }); this.setupScripts.push({ From abdcf4a839ce6b69b066d385749292e44e5019bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Thu, 19 Nov 2020 15:02:07 +0100 Subject: [PATCH 05/10] changed regex in parser definition for command parameters --- engine/parser.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/parser.def b/engine/parser.def index 7d9e9cc6..b08174ca 100644 --- a/engine/parser.def +++ b/engine/parser.def @@ -52,7 +52,7 @@ stepline = !"--" string __ { return { "stepline": text()}; } string "string" - = [a-zA-Z0-9.(),;:/-_-" ]+ { return text(); } + = [^\r\n]+ { return text(); } _ "whitespace" = [ \t]* From d447c4b6986b663f1a52905011e1ba70ee54c261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Thu, 19 Nov 2020 18:16:22 +0100 Subject: [PATCH 06/10] changed cobiGenJava command --- engine/command.ts | 3 +-- playbooks/cobigen-cli/index.asciidoc | 3 ++- runners/katacoda/index.ts | 12 +++++++++++- runners/katacoda/templates/cobiGenJava.md | 7 ++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/engine/command.ts b/engine/command.ts index ce3aa198..6eafb986 100644 --- a/engine/command.ts +++ b/engine/command.ts @@ -3,7 +3,6 @@ export class Command{ public parameterString: string; get parameters(): any[] { - let params = JSON.parse("[" + this.parameterString + "]"); - return params; + return JSON.parse("[" + this.parameterString + "]"); } } \ No newline at end of file diff --git a/playbooks/cobigen-cli/index.asciidoc b/playbooks/cobigen-cli/index.asciidoc index 48cdddcf..9622c9cc 100644 --- a/playbooks/cobigen-cli/index.asciidoc +++ b/playbooks/cobigen-cli/index.asciidoc @@ -23,6 +23,7 @@ installCobiGen() CobiGen is integrated via plugin in the VS Code IDE. We will use it to generate code from one single java class based on existing templates. [step] -- -cobiGenJava("Test.java",[1,2,3,4]) +cobiGenJava("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java",[1,3,5,6,8]) -- +The CobiGen code generator will generate some java class for you. These contain code for basic CRUD operations, REST service handling and data access. ==== diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 50353b5c..9b9169bc 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -98,6 +98,16 @@ export class Katacoda extends Runner { let params = command.parameters; let cobiGenTemplates = params[1].join(","); + let javaFilePath = new String(params[0]); + let entity = javaFilePath.slice(javaFilePath.lastIndexOf("/") + 1, javaFilePath.lastIndexOf(".")).replace("Entity", ""); + + // remove the last two directories of the path to the entity class + let tmpPath = javaFilePath.split("/").splice(0, javaFilePath.match(/\//g).length - 2).join("/"); + let generatedFiles = []; + generatedFiles.push("devonfw/workspaces/main/" + tmpPath + "/logic/base/usecase/Abstract" + entity + "Uc.java"); + generatedFiles.push("devonfw/workspaces/main/" + tmpPath + "/service/impl/rest/" + entity + "managementRestServiceImpl.java"); + generatedFiles.push("devonfw/workspaces/main/" + tmpPath + "/dataaccess/api/repo/" + entity + "Repository.java"); + this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" }); this.setupScripts.push({ "name": "Install CobiGen plugin", @@ -109,7 +119,7 @@ export class Katacoda extends Runner { "title": "CobiGen Java", "text": "step" + this.stepsCount + ".md" }); - this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates }); + this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates, generatedFiles: generatedFiles }); return null; } diff --git a/runners/katacoda/templates/cobiGenJava.md b/runners/katacoda/templates/cobiGenJava.md index 1ed1c905..aaf130ec 100644 --- a/runners/katacoda/templates/cobiGenJava.md +++ b/runners/katacoda/templates/cobiGenJava.md @@ -13,4 +13,9 @@ You can choose the templates CobiGen should use by entering the numbers. `<%= cobiGenTemplates; %>`{{execute}} -<%= textAfter; %> \ No newline at end of file +<%= textAfter; %> + +For example, the following files are generated by CobiGen. +<% for(var i=0; i +`<%=generatedFiles[i]%>`{{open}} +<% } %> \ No newline at end of file From 75951669739cc26b41f637f3eb275bb4057a615c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Fri, 20 Nov 2020 08:34:34 +0100 Subject: [PATCH 07/10] changed textAfter for cobiGenJava --- playbooks/cobigen-cli/index.asciidoc | 25 ++++++++++++++++++++++- runners/katacoda/index.ts | 12 +---------- runners/katacoda/templates/cobiGenJava.md | 7 +------ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/playbooks/cobigen-cli/index.asciidoc b/playbooks/cobigen-cli/index.asciidoc index 9622c9cc..da71d523 100644 --- a/playbooks/cobigen-cli/index.asciidoc +++ b/playbooks/cobigen-cli/index.asciidoc @@ -25,5 +25,28 @@ CobiGen is integrated via plugin in the VS Code IDE. We will use it to generate -- cobiGenJava("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java",[1,3,5,6,8]) -- -The CobiGen code generator will generate some java class for you. These contain code for basic CRUD operations, REST service handling and data access. +The CobiGen code generator will generate some java classes for you. These contain code for basic CRUD operations, REST service handling and data access. + +For example, the following files are generated by CobiGen when using the specified templates: + +(1) CRUD logic: Generates the logic layer and implementations for some use cases. +- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/logic/impl/CustomermanagementImpl.java`{{open}} +- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/logic/impl/usecase/UcManageCustomerImpl.java`{{open}} +- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/logic/impl/usecase/UcFindCustomerImpl.java`{{open}} +- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/logic/api/Customermanagement.java`{{open}} + +(3) CRUD REST services: Generates the service layer with CRUD operations for using in REST services. +- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/service/api/rest/CustomermanagementRestService.java`{{open}} +- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/service/impl/rest/CustomermanagementRestServiceImpl.java`{{open}} + +(5) TO's: Generates the related Transfer Objects. +- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/logic/api/to/CustomerEto.java`{{open}} +- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/logic/api/to/CustomerSearchCriteriaTo.java`{{open}} + +(6) Entity infrastructure: Creates the entity main interface and edits (by a merge) the current entity to extend the newly generated classes. +- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/common/api/Customer.java`{{open}} +- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java`{{open}} (changed) + +(8) CRUD SpringData Repository: Generates the entity repository (that contains the CRUD operations) in the data access layer. +- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/repo/CustomerRepository.java`{{open}} ==== diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 9b9169bc..09d8fe68 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -97,16 +97,6 @@ export class Katacoda extends Runner { runCobiGenJava(step: Step, command: Command): RunResult { let params = command.parameters; let cobiGenTemplates = params[1].join(","); - - let javaFilePath = new String(params[0]); - let entity = javaFilePath.slice(javaFilePath.lastIndexOf("/") + 1, javaFilePath.lastIndexOf(".")).replace("Entity", ""); - - // remove the last two directories of the path to the entity class - let tmpPath = javaFilePath.split("/").splice(0, javaFilePath.match(/\//g).length - 2).join("/"); - let generatedFiles = []; - generatedFiles.push("devonfw/workspaces/main/" + tmpPath + "/logic/base/usecase/Abstract" + entity + "Uc.java"); - generatedFiles.push("devonfw/workspaces/main/" + tmpPath + "/service/impl/rest/" + entity + "managementRestServiceImpl.java"); - generatedFiles.push("devonfw/workspaces/main/" + tmpPath + "/dataaccess/api/repo/" + entity + "Repository.java"); this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" }); this.setupScripts.push({ @@ -119,7 +109,7 @@ export class Katacoda extends Runner { "title": "CobiGen Java", "text": "step" + this.stepsCount + ".md" }); - this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates, generatedFiles: generatedFiles }); + this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates }); return null; } diff --git a/runners/katacoda/templates/cobiGenJava.md b/runners/katacoda/templates/cobiGenJava.md index aaf130ec..1ed1c905 100644 --- a/runners/katacoda/templates/cobiGenJava.md +++ b/runners/katacoda/templates/cobiGenJava.md @@ -13,9 +13,4 @@ You can choose the templates CobiGen should use by entering the numbers. `<%= cobiGenTemplates; %>`{{execute}} -<%= textAfter; %> - -For example, the following files are generated by CobiGen. -<% for(var i=0; i -`<%=generatedFiles[i]%>`{{open}} -<% } %> \ No newline at end of file +<%= textAfter; %> \ No newline at end of file From d96e94b6d52b44d4b3de644b706a238678adbfbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Fri, 20 Nov 2020 09:11:58 +0100 Subject: [PATCH 08/10] changed cobiGenJava.md --- runners/katacoda/templates/cobiGenJava.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/katacoda/templates/cobiGenJava.md b/runners/katacoda/templates/cobiGenJava.md index 1ed1c905..46c86739 100644 --- a/runners/katacoda/templates/cobiGenJava.md +++ b/runners/katacoda/templates/cobiGenJava.md @@ -9,8 +9,8 @@ You can use the plugin simply via the context menu. Make a right click on the ja A terminal will open on the bottom of the IDE and CobiGen CLI will start. -You can choose the templates CobiGen should use by entering the numbers. +You can choose the templates CobiGen should use by entering the numbers in the terminal of the IDE. -`<%= cobiGenTemplates; %>`{{execute}} +`<%= cobiGenTemplates; %>` <%= textAfter; %> \ No newline at end of file From 1e52fdf89b5b0a7ff241916270a7dcd1b759473c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Mon, 23 Nov 2020 08:55:41 +0100 Subject: [PATCH 09/10] added empty method runCobiGenJava in console runner --- runners/console/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runners/console/index.ts b/runners/console/index.ts index 57cc2201..b91c48ba 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -35,6 +35,10 @@ export class Console extends Runner { return null; } + runCobiGenJava(step: Step, command: Command): RunResult { + return null; + } + async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { let installedTools = command.parameters[0]; From 251ab2035ae1abefbdd8b1b96caafa770411fd33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Mon, 23 Nov 2020 08:56:53 +0100 Subject: [PATCH 10/10] added empty method assertCobiGenJava in console runner --- runners/console/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runners/console/index.ts b/runners/console/index.ts index b91c48ba..a63478fa 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -58,6 +58,10 @@ export class Console extends Runner { console.log("assertInstallCobiGen"); } + async assertCobiGenJava(step: Step, command: Command, result: RunResult) { + console.log("assertCobiGenJava"); + } + private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { if(result.returnCode != 0) return;