Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion engine/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export class Command{
public name: string;
public parameters: string;
public parameterString: string;

get parameters(): any[] {
return JSON.parse("[" + this.parameterString + "]");
}
}
2 changes: 1 addition & 1 deletion engine/parser.def
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ stepline
= !"--" string __ { return { "stepline": text()}; }

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

_ "whitespace"
= [ \t]*
Expand Down
2 changes: 1 addition & 1 deletion engine/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
34 changes: 33 additions & 1 deletion playbooks/cobigen-cli/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,43 @@ 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
[step]
--
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("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 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}}
====
14 changes: 11 additions & 3 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,8 +35,12 @@ 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.replace(/\[/, "").replace("\]", "").replace(/mvn/, "maven").split(",");
let installedTools = command.parameters[0];

let assert = new Assertions()
.noErrorCode(result)
Expand All @@ -46,6 +49,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]));
}
}
Expand All @@ -54,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;

Expand Down
23 changes: 21 additions & 2 deletions runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export class Katacoda extends Runner {
}

runInstallDevonfwIde(step: Step, command: Command): RunResult {
let params = command.parameters.replace(/\[/, "").replace("\]", "").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: 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({
Expand All @@ -94,6 +94,25 @@ export class Katacoda extends Runner {
return null;
}

runCobiGenJava(step: Step, command: Command): RunResult {
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({
"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);
Expand Down
16 changes: 16 additions & 0 deletions runners/katacoda/templates/cobiGenJava.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%= text; %>

## CobiGen Java

Open the following java file in the IDE.
`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'.

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 in the terminal of the IDE.

`<%= cobiGenTemplates; %>`

<%= textAfter; %>
Binary file not shown.
6 changes: 6 additions & 0 deletions runners/katacoda/templates/scripts/installCobiGenPlugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

apt install libarchive-tools -y
cd /root/setup/
bsdtar -xvf <%= vsixFile; %> - extension
mv extension /opt/.katacodacode/extensions/<%= pluginName; %>