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
2 changes: 1 addition & 1 deletion engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Engine {
}

for (let runnerIndex in this.environment.runners) {
(await this.getRunner(this.environment.runners[runnerIndex])).destroy(this.playbook);
await (await this.getRunner(this.environment.runners[runnerIndex])).destroy(this.playbook);
}
}

Expand Down
13 changes: 8 additions & 5 deletions engine/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,17 @@ export abstract class Runner {
}
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
}

protected createFolder(path: string, deleteFolerIfExist: boolean) {
protected createFolder(path: string, deleteFolderIfExist: boolean) {
if(fs.existsSync(path)) {
if(deleteFolerIfExist) {
rimraf.sync(path);
fs.mkdirSync(path, { recursive: true });
if(deleteFolderIfExist) {
try {
rimraf.sync(path);
} catch(e) {
console.log("Error deleting foler " + path, e);
}
} else return path;
}
fs.mkdirSync(path, { recursive: true });
Expand Down
2 changes: 1 addition & 1 deletion engine/wikiRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export abstract class WikiRunner extends Runner {
this.outputPathTutorial = this.createFolder(path.join(outputDirectory, playbook.name), true);
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {

}

Expand Down
121 changes: 63 additions & 58 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class Console extends Runner {
this.env = process.env;
}

destroy(playbook: Playbook): void {
this.cleanUp();
async destroy(playbook: Playbook): Promise<void> {
await this.cleanUp();
}

runInstallDevonfwIde(runCommand: RunCommand): RunResult {
Expand Down Expand Up @@ -361,7 +361,7 @@ export class Console extends Runner {
assert.directoryExits(path.join(this.getWorkingDirectory(), "devonfw", "software", tool));
}
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -379,7 +379,7 @@ export class Console extends Runner {
.fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cobigen.jar"))
.fileExits(path.join(this.getWorkingDirectory(), "devonfw", "software", "cobigen-cli", "cobigen"));
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -393,7 +393,7 @@ export class Console extends Runner {
.directoryExits(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0], "core", "target"))
.directoryExits(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0], "server", "target"));
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -405,7 +405,7 @@ export class Console extends Runner {
.noException(result)
.fileExits(path.join(this.getWorkingDirectory(), "devonfw", "workspaces", "main", runCommand.command.parameters[0]));
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -423,7 +423,7 @@ export class Console extends Runner {
.directoryExits(path.join(workspaceDir, runCommand.command.parameters[0], "server", "src", "main", "java"))
.fileExits(path.join(workspaceDir, runCommand.command.parameters[0], "core", "src", "main", "java", "com", "example", "application", runCommand.command.parameters[0], "SpringBootApp.java"));
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -435,7 +435,7 @@ export class Console extends Runner {
.noException(result)
.fileExits(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0]));
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -456,7 +456,7 @@ export class Console extends Runner {
.fileExits(filepath)
.fileContains(filepath, content);
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -475,18 +475,18 @@ export class Console extends Runner {
await this.sleep(runCommand.command.parameters[1].startupTime);

if(!runCommand.command.parameters[1].port) {
this.killAsyncProcesses();
await this.killAsyncProcesses();
throw new Error("Missing arguments for command dockerCompose. You have to specify a port and a path for the server. For further information read the function documentation.");
} else {
let isReachable = await assert.serverIsReachable(runCommand.command.parameters[1].port, runCommand.command.parameters[1].path);
if(!isReachable) {
this.killAsyncProcesses();
await this.killAsyncProcesses();
throw new Error("The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + runCommand.command.parameters[1].port + "/" + runCommand.command.parameters[1].path);
}
}
}
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -505,18 +505,18 @@ export class Console extends Runner {
await this.sleep(runCommand.command.parameters[1].startupTime);

if(!runCommand.command.parameters[1].port || !runCommand.command.parameters[1].path) {
this.killAsyncProcesses();
await this.killAsyncProcesses();
throw new Error("Missing arguments for command runServerJava. You have to specify a port and a path for the server. For further information read the function documentation.");
} else {
let isReachable = await assert.serverIsReachable(runCommand.command.parameters[1].port, runCommand.command.parameters[1].path);
if(!isReachable) {
this.killAsyncProcesses();
await this.killAsyncProcesses();
throw new Error("The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + runCommand.command.parameters[1].port + "/" + runCommand.command.parameters[1].path)
}
}
}
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -534,7 +534,7 @@ export class Console extends Runner {
.directoryNotEmpty(path.join(this.getVariable(this.workspaceDirectory), runCommand.command.parameters[0], repoName))
.repositoryIsClean(directorypath);
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -552,7 +552,7 @@ export class Console extends Runner {
.directoryNotEmpty(path.join(projectDir, "node_modules"));
}
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -570,7 +570,7 @@ export class Console extends Runner {
.directoryNotEmpty(directory)
.fileExits(path.join(directory, runCommand.command.parameters[1]));
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -589,18 +589,18 @@ export class Console extends Runner {
await this.sleep(runCommand.command.parameters[1].startupTime);

if(!runCommand.command.parameters[1].port) {
this.killAsyncProcesses();
await this.killAsyncProcesses();
throw new Error("Missing arguments for command runClientNg. You have to specify a port for the server. For further information read the function documentation.");
} else {
let isReachable = await assert.serverIsReachable(runCommand.command.parameters[1].port, runCommand.command.parameters[1].path);
if(!isReachable) {
this.killAsyncProcesses();
await this.killAsyncProcesses();
throw new Error("The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + runCommand.command.parameters[1].port + "/" + runCommand.command.parameters[1].path)
}
}
}
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -625,7 +625,7 @@ export class Console extends Runner {
.directoryNotEmpty(path.join(projectPath, outputpath));

} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -638,7 +638,7 @@ export class Console extends Runner {
.noException(result)
.directoryExits(folderPath);
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -653,7 +653,7 @@ export class Console extends Runner {
.directoryNotEmpty(templatesDir);

} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -667,7 +667,7 @@ export class Console extends Runner {
.directoryExits(projectDir)
.directoryNotEmpty(projectDir);
} catch(error) {
this.cleanUp();
await this.cleanUp();
throw error;
}
}
Expand All @@ -690,46 +690,51 @@ export class Console extends Runner {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}

private killAsyncProcesses() {
if(this.asyncProcesses.length > 0) {
psList().then(processes => {
// Get all processes and check if they are child orprocesses of the processes that should be terminated. If so, kill them first.
let killProcessesRecursively = function(processes, processIdToKill) {
let childProcesses = processes.filter(process => {
return process.ppid == processIdToKill;
});

if(childProcesses.length > 0) {
childProcesses.forEach(childProcess => {
killProcessesRecursively(processes, childProcess.pid)
});
}
private async killAsyncProcesses(): Promise<void> {
let killProcessesRecursively = function(processes: psList.ProcessDescriptor[], processIdToKill: number) {
let childProcesses = processes.filter(process => {
return process.ppid == processIdToKill;
});

process.kill(processIdToKill);
if(childProcesses.length > 0) {
for(let childProcess of childProcesses) {
killProcessesRecursively(processes, childProcess.pid)
}
}

try {
process.kill(processIdToKill);
} catch(e) {
console.error("Error killing id " + processIdToKill, e);
}
}

this.asyncProcesses.forEach(asyncProcess => {
killProcessesRecursively(processes, asyncProcess.pid);
});
}).then(() => {
//Check if there are still running processes on the given ports
this.asyncProcesses.forEach(asyncProcess => {
findProcess("port", asyncProcess.port).then((processes) => {
if(processes.length > 0) {
processes.forEach(proc => {
if(proc.name == asyncProcess.name || proc.name == asyncProcess.name + ".exe") {
process.kill(proc.pid);
}
});
if(this.asyncProcesses.length > 0) {
let processes: psList.ProcessDescriptor[] = Array.from((await psList()).values());
for(let asyncProcess of this.asyncProcesses) {
killProcessesRecursively(processes, asyncProcess.pid);
}

//Check if there are still running processes on the given ports
for(let asyncProcess of this.asyncProcesses) {
let processes: any[] = await findProcess("port", asyncProcess.port);
if(processes.length > 0) {
for(let proc of processes) {
if(proc.name == asyncProcess.name || proc.name == asyncProcess.name + ".exe") {
try {
process.kill(proc.pid);
} catch(e) {
console.error("Error killing id " + proc.pid, e);
}
}
})
});
})
}
}
}
}
}

private cleanUp(): void {
this.killAsyncProcesses();
private async cleanUp(): Promise<void> {
await this.killAsyncProcesses();
ConsoleUtils.restoreDevonDirectory();
}
}
2 changes: 1 addition & 1 deletion runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class Katacoda extends Runner {
this.assetManager = new KatacodaAssetManager(path.join(this.outputPathTutorial, "assets"));
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
let tutorialDirectoryName = path.basename(playbook.path);
this.renderTemplate("intro.md", path.join(this.outputPathTutorial, "intro.md"), { description: playbook.description, tutorialPath: tutorialDirectoryName });
fs.writeFileSync(this.outputPathTutorial + 'finish.md', "");
Expand Down
2 changes: 1 addition & 1 deletion runners/vscode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class VsCode extends Runner {
});
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
this.cleanUp();
}

Expand Down
2 changes: 1 addition & 1 deletion runners/wikiConsole/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class WikiConsole extends WikiRunner {
super.init(playbook);
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
super.destroy(playbook);
}

Expand Down
2 changes: 1 addition & 1 deletion runners/wikiEclipse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class WikiEclipse extends WikiRunner {
super.init(playbook);
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
super.destroy(playbook);
}
}
2 changes: 1 addition & 1 deletion runners/wikiEditor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class WikiEditor extends WikiRunner {
super.init(playbook);
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
super.destroy(playbook);
}
}
2 changes: 1 addition & 1 deletion runners/wikiVsCode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class WikiVsCode extends WikiRunner {
super.init(playbook);
}

destroy(playbook: Playbook): void {
async destroy(playbook: Playbook): Promise<void> {
super.destroy(playbook);
}
}