Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #177: Error log pop out in Toggle Developer tools #176

Merged
merged 1 commit into from
Apr 12, 2018
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
12 changes: 7 additions & 5 deletions src/Tomcat/TomcatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import { TomcatServer } from "./TomcatServer";
import { WarPackage } from "./WarPackage";

export class TomcatController {
private _outputChannel: vscode.OutputChannel;
constructor(private _tomcatModel: TomcatModel, private _extensionPath: string) {
this._outputChannel = vscode.window.createOutputChannel('vscode-tomcat');
}

public async deleteServer(tomcatServer: TomcatServer): Promise<void> {
Expand Down Expand Up @@ -131,7 +133,7 @@ export class TomcatController {
const newName: string = await vscode.window.showInputBox({
prompt: 'input a new server name',
validateInput: (name: string): string => {
if (!name.match(/^[\w.-]+$/)) {
if (name && !name.match(/^[\w.-]+$/)) {
return 'please input a valid server name';
} else if (this._tomcatModel.getTomcatServer(name)) {
return 'the name was already taken, please re-input';
Expand All @@ -155,7 +157,7 @@ export class TomcatController {
return;
}
Utility.trackTelemetryStep(restart ? 'restart' : 'stop');
await Utility.executeCMD(server.outputChannel, 'java', { shell: true }, ...server.jvmOptions.concat('stop'));
await Utility.executeCMD(this._outputChannel, tomcatServer.getName(), 'java', { shell: true }, ...server.jvmOptions.concat('stop'));
if (!restart) {
server.clearDebugInfo();
}
Expand Down Expand Up @@ -251,7 +253,7 @@ export class TomcatController {
if (element.isStarted()) {
this.stopOrRestartServer(element);
}
element.outputChannel.dispose();
this._outputChannel.dispose();
});
this._tomcatModel.saveServerListSync();
}
Expand Down Expand Up @@ -289,7 +291,7 @@ export class TomcatController {
await fse.remove(appPath);
await fse.mkdirs(appPath);
Utility.trackTelemetryStep('deploy war');
await Utility.executeCMD(serverInfo.outputChannel, 'jar', { cwd: appPath }, 'xvf', `${packagePath}`);
await Utility.executeCMD(this._outputChannel, 'jar', serverInfo.getName(), { cwd: appPath }, 'xvf', `${packagePath}`);
vscode.commands.executeCommand('tomcat.tree.refresh');
}

Expand Down Expand Up @@ -353,7 +355,7 @@ export class TomcatController {
startArguments = [`${Constants.DEBUG_ARGUMENT_KEY}${serverInfo.getDebugPort()}`].concat(startArguments);
}
startArguments.push('start');
const javaProcess: Promise<void> = Utility.executeCMD(serverInfo.outputChannel, 'java', { shell: true }, ...startArguments);
const javaProcess: Promise<void> = Utility.executeCMD(this._outputChannel, serverInfo.getName(), 'java', { shell: true }, ...startArguments);
serverInfo.setStarted(true);
this.startDebugSession(serverInfo);
await javaProcess;
Expand Down
1 change: 0 additions & 1 deletion src/Tomcat/TomcatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export class TomcatModel {
if (!_.isEmpty(oldServer)) {
fse.remove(tomcatServer.getStoragePath());
this.saveServerList();
tomcatServer.outputChannel.dispose();
return true;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Tomcat/TomcatServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class TomcatServer extends vscode.TreeItem implements vscode.QuickPickIte
public description: string;
public jvmOptions: string[];
public jvmOptionFile: string;
public outputChannel: vscode.OutputChannel;
private _state: ServerState = ServerState.IdleServer;
private _isDebugging: boolean = false;
private _debugPort: number;
Expand All @@ -22,7 +21,6 @@ export class TomcatServer extends vscode.TreeItem implements vscode.QuickPickIte
constructor(private _name: string, private _installPath: string, private _storagePath: string) {
super(_name);
this.label = _name;
this.outputChannel = vscode.window.createOutputChannel(`tomcat_${this._name}`);
this.jvmOptionFile = path.join(this._storagePath, Constants.JVM_OPTION_FILE);
this._configurationPath = path.join(this._storagePath, 'conf', 'server.xml');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ import { localize } from './localize';

/* tslint:disable:no-any */
export namespace Utility {
export async function executeCMD(outputPane: vscode.OutputChannel, command: string, options: child_process.SpawnOptions, ...args: string[]): Promise<void> {
export async function executeCMD(outputPane: vscode.OutputChannel, serverName: string, command: string, options: child_process.SpawnOptions, ...args: string[]): Promise<void> {
await new Promise((resolve: () => void, reject: (e: Error) => void): void => {
outputPane.show();
let stderr: string = '';
const p: child_process.ChildProcess = child_process.spawn(command, args, options);
p.stdout.on('data', (data: string | Buffer): void =>
outputPane.append(data.toString()));
outputPane.append(`[${serverName}]: ${data.toString()}`));
p.stderr.on('data', (data: string | Buffer) => {
stderr = stderr.concat(data.toString());
outputPane.append(data.toString());
outputPane.append(`[${serverName}]: ${data.toString()}`);
});
p.on('error', (err: Error) => {
reject(err);
Expand Down