From 49e7e4c35a2da711892c8ff98f342c02e55aeb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Mon, 16 Nov 2020 17:29:43 +0100 Subject: [PATCH 1/7] command installDevonfwIde for console runner --- engine/runner.ts | 1 + runners/console/index.ts | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/engine/runner.ts b/engine/runner.ts index 94cfe3a7..ac5a4c0c 100644 --- a/engine/runner.ts +++ b/engine/runner.ts @@ -106,5 +106,6 @@ export abstract class Runner { } else return } fs.mkdirSync(path, { recursive: true }); + return path; } } \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index 52c1658a..01a76746 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -3,12 +3,32 @@ import { RunResult } from "../../engine/run_result"; import { Step } from "../../engine/step"; import { Command } from "../../engine/command"; import { Assertions } from "../../assertions"; +import * as path from 'path'; +import * as child_process from "child_process"; +import * as fs from "fs"; export class Console extends Runner { runInstallDevonfwIde(step: Step, command: Command): RunResult { - //TODO let result = new RunResult(); + result.returnCode = 1; + + let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true); + child_process.execSync("cd " + settingsDir + " && git clone https://github.com/devonfw/ide-settings.git settings"); + + let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").trim(); + let tools = "DEVON_IDE_TOOLS=(" + params + ")" + fs.writeFileSync(path.join(settingsDir, "settings", "devon.properties"), tools); + fs.renameSync(path.join(settingsDir, "settings"), path.join(settingsDir, "settings.git")); + child_process.execSync("cd " + path.join(settingsDir, "settings.git") + " && git add -A && git config user.email \"devonfw\" && git config user.name \"devonfw\" && git commit -m \"devonfw\""); + + let installDir = path.join(this.getWorkingDirectory(), "devonfw"); + this.createFolder(installDir, false); + + child_process.execSync("cd " + installDir + " && curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9"); + child_process.execSync("cd " + installDir + " && tar -xf devonfw.tar.gz"); + child_process.execSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/")); + result.returnCode = 0; return result; } @@ -19,6 +39,7 @@ export class Console extends Runner { async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { console.log("assertInstallDevonfwIde"); + console.log(result) new Assertions() .noErrorCode(result) .noException(result); From 245c1422be3ebcbcdf4628402446284c0c9fa9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Tue, 17 Nov 2020 13:37:04 +0100 Subject: [PATCH 2/7] modified command installDevonfwIde for console runner --- engine/runner.ts | 16 +++++++++++++++- runners/console/index.ts | 21 +++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/engine/runner.ts b/engine/runner.ts index ac5a4c0c..d563cb1d 100644 --- a/engine/runner.ts +++ b/engine/runner.ts @@ -3,6 +3,7 @@ import { RunResult } from "./run_result"; import { Playbook } from "./playbook"; import { Step } from "./step"; import * as fs from 'fs'; +import * as path from 'path'; const nameof = (name: Extract): string => name; @@ -101,11 +102,24 @@ export abstract class Runner { protected createFolder(path: string, deleteFolerIfExist: boolean) { if(fs.existsSync(path)) { if(deleteFolerIfExist) { - fs.rmdirSync(path, { recursive: true }); + this.removeDirectoryRecursively(path); //just rmdirSync work not properly on linux fs.mkdirSync(path, { recursive: true }); } else return } fs.mkdirSync(path, { recursive: true }); return path; } + + private removeDirectoryRecursively(directoryPath: string) { + let dir = fs.readdirSync(directoryPath); + dir.forEach(file => { + let currentPath = path.join(directoryPath, file); + if(fs.lstatSync(currentPath).isDirectory()) { + this.removeDirectoryRecursively(currentPath) + } else { + fs.unlinkSync(currentPath); + } + }); + fs.rmdirSync(directoryPath); + } } \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index 01a76746..8f621d2e 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -6,6 +6,7 @@ import { Assertions } from "../../assertions"; import * as path from 'path'; import * as child_process from "child_process"; import * as fs from "fs"; +import { ChildProcess } from "child_process"; export class Console extends Runner { @@ -14,20 +15,20 @@ export class Console extends Runner { result.returnCode = 1; let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true); - child_process.execSync("cd " + settingsDir + " && git clone https://github.com/devonfw/ide-settings.git settings"); + this.executeCommandSync("git clone https://github.com/devonfw/ide-settings.git settings", settingsDir); let params = command.parameters.replace(/\[/, "").replace("\]", "").replace(/,/, " ").trim(); - let tools = "DEVON_IDE_TOOLS=(" + params + ")" + let tools = "DEVON_IDE_TOOLS=(" + params + ")"; fs.writeFileSync(path.join(settingsDir, "settings", "devon.properties"), tools); fs.renameSync(path.join(settingsDir, "settings"), path.join(settingsDir, "settings.git")); - child_process.execSync("cd " + path.join(settingsDir, "settings.git") + " && git add -A && git config user.email \"devonfw\" && git config user.name \"devonfw\" && git commit -m \"devonfw\""); - + this.executeCommandSync("git add -A && git config user.email \"devonfw\" && git config user.name \"devonfw\" && git commit -m \"devonfw\"", path.join(settingsDir, "settings.git")); + let installDir = path.join(this.getWorkingDirectory(), "devonfw"); this.createFolder(installDir, false); - - child_process.execSync("cd " + installDir + " && curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9"); - child_process.execSync("cd " + installDir + " && tar -xf devonfw.tar.gz"); - child_process.execSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/")); + this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir); + this.executeCommandSync("tar -xf devonfw.tar.gz", installDir); + + child_process.spawnSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), { shell: true, input: "yes"}); result.returnCode = 0; return result; @@ -48,4 +49,8 @@ export class Console extends Runner { async assertInstallCobiGen(step: Step, command: Command, result: RunResult) { console.log("assertInstallCobiGen"); } + + private executeCommandSync(command: string, directory: string) { + child_process.execSync("cd " + path.join(directory) + " && " + command); + } } \ No newline at end of file From 42b48906877272d3e4574ec07772bdc8d9dd5d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Tue, 17 Nov 2020 14:11:42 +0100 Subject: [PATCH 3/7] modified command installDevonfwIde for console runner --- runners/console/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index 8f621d2e..92e83427 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -24,7 +24,7 @@ export class Console extends Runner { this.executeCommandSync("git add -A && git config user.email \"devonfw\" && git config user.name \"devonfw\" && git commit -m \"devonfw\"", path.join(settingsDir, "settings.git")); let installDir = path.join(this.getWorkingDirectory(), "devonfw"); - this.createFolder(installDir, false); + this.createFolder(installDir, true); this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir); this.executeCommandSync("tar -xf devonfw.tar.gz", installDir); @@ -39,11 +39,11 @@ export class Console extends Runner { } async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { - console.log("assertInstallDevonfwIde"); - console.log(result) new Assertions() .noErrorCode(result) - .noException(result); + .noException(result) + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw")) + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software")); } async assertInstallCobiGen(step: Step, command: Command, result: RunResult) { From 7d35b7bd5216233948a42d01569a199c1a007740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Tue, 17 Nov 2020 14:13:24 +0100 Subject: [PATCH 4/7] modified command installDevonfwIde for console runner --- runners/console/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index 92e83427..a2db3165 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -6,7 +6,6 @@ import { Assertions } from "../../assertions"; import * as path from 'path'; import * as child_process from "child_process"; import * as fs from "fs"; -import { ChildProcess } from "child_process"; export class Console extends Runner { @@ -42,7 +41,6 @@ export class Console extends Runner { new Assertions() .noErrorCode(result) .noException(result) - .directoryExits(path.join(this.getWorkingDirectory(), "devonfw")) .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software")); } From c8ea658a2d221bea35c279d0ea3b97acb76d86c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Tue, 17 Nov 2020 14:31:16 +0100 Subject: [PATCH 5/7] added rimraf module for folder deletion --- engine/runner.ts | 17 ++------------ package-lock.json | 58 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/engine/runner.ts b/engine/runner.ts index d563cb1d..b43118e4 100644 --- a/engine/runner.ts +++ b/engine/runner.ts @@ -3,7 +3,7 @@ import { RunResult } from "./run_result"; import { Playbook } from "./playbook"; import { Step } from "./step"; import * as fs from 'fs'; -import * as path from 'path'; +import * as rimraf from 'rimraf'; const nameof = (name: Extract): string => name; @@ -102,24 +102,11 @@ export abstract class Runner { protected createFolder(path: string, deleteFolerIfExist: boolean) { if(fs.existsSync(path)) { if(deleteFolerIfExist) { - this.removeDirectoryRecursively(path); //just rmdirSync work not properly on linux + rimraf.sync(path); fs.mkdirSync(path, { recursive: true }); } else return } fs.mkdirSync(path, { recursive: true }); return path; } - - private removeDirectoryRecursively(directoryPath: string) { - let dir = fs.readdirSync(directoryPath); - dir.forEach(file => { - let currentPath = path.join(directoryPath, file); - if(fs.lstatSync(currentPath).isDirectory()) { - this.removeDirectoryRecursively(currentPath) - } else { - fs.unlinkSync(currentPath); - } - }); - fs.rmdirSync(directoryPath); - } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8024461d..1330cb1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -110,16 +110,48 @@ "minimatch": "^3.0.4" } }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, "is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", @@ -144,6 +176,19 @@ "brace-expansion": "^1.1.7" } }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, "pegjs": { "version": "0.10.0", "resolved": "https://registry.npmjs.org/pegjs/-/pegjs-0.10.0.tgz", @@ -154,6 +199,14 @@ "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "requires": { + "glob": "^7.1.3" + } + }, "string-width": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz", @@ -221,6 +274,11 @@ } } }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, "y18n": { "version": "5.0.5", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.5.tgz", diff --git a/package.json b/package.json index e0faecd1..d2dfd695 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@types/node": "^14.14.2", "ejs": "^3.1.5", "pegjs": "^0.10.0", + "rimraf": "^3.0.2", "ts-pegjs": "^0.2.7", "yargs": "^16.1.0" }, From 1ffd200d95ae9981fea64ad30970608cffdcca55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Tue, 17 Nov 2020 15:56:22 +0100 Subject: [PATCH 6/7] modified command installDevonfwIde for console runner --- runners/console/index.ts | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index a2db3165..e9dc5d34 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -11,25 +11,24 @@ export class Console extends Runner { runInstallDevonfwIde(step: Step, command: Command): RunResult { let result = new RunResult(); - result.returnCode = 1; + result.returnCode = 0; let settingsDir = this.createFolder(path.join(this.getWorkingDirectory(), "devonfw-settings"), true); - this.executeCommandSync("git clone https://github.com/devonfw/ide-settings.git settings", settingsDir); + 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 + ")"; 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")); + 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); let installDir = path.join(this.getWorkingDirectory(), "devonfw"); this.createFolder(installDir, true); - this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir); - this.executeCommandSync("tar -xf devonfw.tar.gz", installDir); + this.executeCommandSync("curl -L -o devonfw.tar.gz https://bit.ly/2BCkFa9", installDir, result); + this.executeCommandSync("tar -xf devonfw.tar.gz", installDir, result); - child_process.spawnSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), { shell: true, input: "yes"}); + this.executeCommandSync(path.join(installDir, "setup") + " " + path.join(settingsDir, "settings.git").replace(/\\/g, "/"), "", result, "yes"); - result.returnCode = 0; return result; } @@ -38,17 +37,31 @@ export class Console extends Runner { } async assertInstallDevonfwIde(step: Step, command: Command, result: RunResult) { - new Assertions() + let installedTools = command.parameters.replace(/\[/, "").replace("\]", "").replace(/mvn/, "maven").split(","); + + let assert = new Assertions() .noErrorCode(result) .noException(result) - .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software")); + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software")) + .directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main")); + + for(let i = 0; i < installedTools.length; i++) { + assert.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", installedTools[i])); + } } async assertInstallCobiGen(step: Step, command: Command, result: RunResult) { console.log("assertInstallCobiGen"); } - private executeCommandSync(command: string, directory: string) { - child_process.execSync("cd " + path.join(directory) + " && " + command); + private executeCommandSync(command: string, directory: string, result: RunResult, input?: string) { + if(result.returnCode != 0) return; + + let process = child_process.spawnSync("cd " + path.join(directory) + " && " + command, { shell: true, input: input }); + if(process.status != 0) { + console.log("Error executing command: " + command); + console.log(process.stderr.toString()) + result.returnCode = process.status; + } } } \ No newline at end of file From 95b42e6da5a4f9996ffd9c85add19efbf608bc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20G=C3=BCnther?= Date: Wed, 18 Nov 2020 08:51:12 +0100 Subject: [PATCH 7/7] modified console runner --- runners/console/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/console/index.ts b/runners/console/index.ts index e9dc5d34..d6dcff4e 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -59,8 +59,8 @@ export class Console extends Runner { let process = child_process.spawnSync("cd " + path.join(directory) + " && " + command, { shell: true, input: input }); if(process.status != 0) { - console.log("Error executing command: " + command); - console.log(process.stderr.toString()) + console.log("Error executing command: " + command + " (exit code: " + process.status + ")"); + console.log(process.stderr.toString(), process.stdout.toString()); result.returnCode = process.status; } }