Skip to content

Commit 9bf7fd9

Browse files
Merge pull request #28 from GuentherJulian/feature_katacodaRunCobiGenJava
command runCobiGenJava for katacoda runner
2 parents d19de49 + 251ab20 commit 9bf7fd9

File tree

9 files changed

+94
-9
lines changed

9 files changed

+94
-9
lines changed

engine/command.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
export class Command{
22
public name: string;
3-
public parameters: string;
3+
public parameterString: string;
4+
5+
get parameters(): any[] {
6+
return JSON.parse("[" + this.parameterString + "]");
7+
}
48
}

engine/parser.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ stepline
5252
= !"--" string __ { return { "stepline": text()}; }
5353

5454
string "string"
55-
= [a-zA-Z0-9.(),;:/-_- ]+ { return text(); }
55+
= [^\r\n]+ { return text(); }
5656

5757
_ "whitespace"
5858
= [ \t]*

engine/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class Parser {
5454
let result = re.exec(line);
5555
let retVal = new Command();
5656
retVal.name = result[1].trim();
57-
retVal.parameters = result[2];
57+
retVal.parameterString = result[2];
5858
return retVal;
5959
}
6060

playbooks/cobigen-cli/index.asciidoc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,43 @@ More information about CobiGen on https://devonfw.com/website/pages/docs/master-
1010
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.
1111
[step]
1212
--
13-
installDevonfwIde([java,mvn])
13+
installDevonfwIde(["java","mvn"])
1414
--
1515

1616
Now, you have to download cobigen
1717
[step]
1818
--
1919
installCobiGen()
2020
--
21+
22+
====
23+
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.
24+
[step]
25+
--
26+
cobiGenJava("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java",[1,3,5,6,8])
27+
--
28+
The CobiGen code generator will generate some java classes for you. These contain code for basic CRUD operations, REST service handling and data access.
29+
30+
For example, the following files are generated by CobiGen when using the specified templates:
31+
32+
(1) CRUD logic: Generates the logic layer and implementations for some use cases.
33+
- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/logic/impl/CustomermanagementImpl.java`{{open}}
34+
- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/logic/impl/usecase/UcManageCustomerImpl.java`{{open}}
35+
- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/logic/impl/usecase/UcFindCustomerImpl.java`{{open}}
36+
- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/logic/api/Customermanagement.java`{{open}}
37+
38+
(3) CRUD REST services: Generates the service layer with CRUD operations for using in REST services.
39+
- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/service/api/rest/CustomermanagementRestService.java`{{open}}
40+
- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/service/impl/rest/CustomermanagementRestServiceImpl.java`{{open}}
41+
42+
(5) TO's: Generates the related Transfer Objects.
43+
- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/logic/api/to/CustomerEto.java`{{open}}
44+
- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/logic/api/to/CustomerSearchCriteriaTo.java`{{open}}
45+
46+
(6) Entity infrastructure: Creates the entity main interface and edits (by a merge) the current entity to extend the newly generated classes.
47+
- `devonfw/workspaces/main/cobigenexample/api/src/main/java/com/example/application/cobigenexample/customermanagement/common/api/Customer.java`{{open}}
48+
- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java`{{open}} (changed)
49+
50+
(8) CRUD SpringData Repository: Generates the entity repository (that contains the CRUD operations) in the data access layer.
51+
- `devonfw/workspaces/main/cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/repo/CustomerRepository.java`{{open}}
52+
====

runners/console/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ export class Console extends Runner {
1616
let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true);
1717
this.executeCommandSync("git clone https://github.com/devonfw/ide-settings.git settings", settingsDir, result);
1818

19-
let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").trim();
20-
let tools = "DEVON_IDE_TOOLS=(" + params + ")";
19+
let tools = "DEVON_IDE_TOOLS=(" + command.parameters[0].join(" ") + ")";
2120
fs.writeFileSync(path.join(settingsDir, "settings", "devon.properties"), tools);
2221
fs.renameSync(path.join(settingsDir, "settings"), path.join(settingsDir, "settings.git"));
2322
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);
@@ -36,8 +35,12 @@ export class Console extends Runner {
3635
return null;
3736
}
3837

38+
runCobiGenJava(step: Step, command: Command): RunResult {
39+
return null;
40+
}
41+
3942
async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) {
40-
let installedTools = command.parameters.replace(/\[/, "").replace("\]", "").replace(/mvn/, "maven").split(",");
43+
let installedTools = command.parameters[0];
4144

4245
let assert = new Assertions()
4346
.noErrorCode(result)
@@ -46,6 +49,7 @@ export class Console extends Runner {
4649
.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main"));
4750

4851
for(let i = 0; i < installedTools.length; i++) {
52+
if(installedTools[i] == "mvn") installedTools[i] = "maven";
4953
assert.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", installedTools[i]));
5054
}
5155
}
@@ -54,6 +58,10 @@ export class Console extends Runner {
5458
console.log("assertInstallCobiGen");
5559
}
5660

61+
async assertCobiGenJava(step: Step, command: Command, result: RunResult) {
62+
console.log("assertCobiGenJava");
63+
}
64+
5765
private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) {
5866
if(result.returnCode != 0) return;
5967

runners/katacoda/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export class Katacoda extends Runner {
6666
}
6767

6868
runInstallDevonfwIde(step: Step, command: Command): RunResult {
69-
let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").replace(/vscode/,"").replace(/eclipse/, "").trim();
69+
let tools = command.parameters[0].join(" ").replace(/vscode/,"").replace(/eclipse/, "").trim();
7070

7171
// create script to download devonfw ide settings
72-
this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: params, cloneDir: "/root/devonfw-settings/"});
72+
this.renderTemplate(path.join("scripts", "cloneDevonfwIdeSettings.sh"), path.join(this.setupDir, "cloneDevonfwIdeSettings.sh"), { tools: tools, cloneDir: "/root/devonfw-settings/"});
7373

7474
// add the script to the setup scripts for executing it at the beginning of the tutorial
7575
this.setupScripts.push({
@@ -94,6 +94,25 @@ export class Katacoda extends Runner {
9494
return null;
9595
}
9696

97+
runCobiGenJava(step: Step, command: Command): RunResult {
98+
let params = command.parameters;
99+
let cobiGenTemplates = params[1].join(",");
100+
101+
this.renderTemplate(path.join("scripts", "installCobiGenPlugin.sh"), path.join(this.setupDir, "installCobiGenPlugin.sh"), { vsixFile: "cobigen-0.0.1.vsix", pluginName: "cobigen" });
102+
this.setupScripts.push({
103+
"name": "Install CobiGen plugin",
104+
"script": "installCobiGenPlugin.sh"
105+
});
106+
this.assetManager.registerFile(path.join(this.getRunnerDirectory(), "templates", "files", "cobigen-0.0.1.vsix"), "setup/cobigen-0.0.1.vsix", "/root/setup", true)
107+
108+
this.steps.push({
109+
"title": "CobiGen Java",
110+
"text": "step" + this.stepsCount + ".md"
111+
});
112+
this.renderTemplate("cobiGenJava.md", this.outputPathTutorial + "step" + (this.stepsCount++) + ".md", { text: step.text, textAfter: step.textAfter, javaFile: params[0], cobiGenTemplates: cobiGenTemplates });
113+
return null;
114+
}
115+
97116
private renderTemplate(name: string, targetPath: string, variables) {
98117
let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8');
99118
let result = ejs.render(template, variables);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<%= text; %>
2+
3+
## CobiGen Java
4+
5+
Open the following java file in the IDE.
6+
`devonfw/workspaces/main/<%= javaFile; %>`{{open}}
7+
8+
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'.
9+
10+
A terminal will open on the bottom of the IDE and CobiGen CLI will start.
11+
12+
You can choose the templates CobiGen should use by entering the numbers in the terminal of the IDE.
13+
14+
`<%= cobiGenTemplates; %>`
15+
16+
<%= textAfter; %>
2.85 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
apt install libarchive-tools -y
4+
cd /root/setup/
5+
bsdtar -xvf <%= vsixFile; %> - extension
6+
mv extension /opt/.katacodacode/extensions/<%= pluginName; %>

0 commit comments

Comments
 (0)