-
Notifications
You must be signed in to change notification settings - Fork 35
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
ignore server port change, ignore server state outside vscode #85
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ export class TomcatController { | |
|
||
if (this._tomcat.deleteServer(tomcatServer)) { | ||
const output: vscode.OutputChannel = this.getOutput(tomcatServer); | ||
this._outputChannels.delete(this.getChannelName(tomcatServer)); | ||
this._outputChannels.delete(`Tomcat_${tomcatServer.getName()}`); | ||
output.dispose(); | ||
} | ||
vscode.commands.executeCommand('tomcat.tree.refresh'); | ||
|
@@ -233,7 +233,7 @@ export class TomcatController { | |
} | ||
|
||
private async getServerUri(serverInfo: TomcatServer, appName?: string): Promise<string> { | ||
const serverPort: string = await Utility.getHttpPort(serverInfo.getServerConfigPath()); | ||
const serverPort: string = await Utility.getPort(serverInfo.getServerConfigPath(), Constants.Port.Http); | ||
if (!serverPort) { | ||
throw new Error('No http port found in server.xml'); | ||
} | ||
|
@@ -247,6 +247,10 @@ export class TomcatController { | |
const serverName: string = serverInfo.getName(); | ||
let watcher: chokidar.FSWatcher; | ||
const serverUri: string = await this.getServerUri(serverInfo, appName); | ||
const serverConfig: string = serverInfo.getServerConfigPath(); | ||
const serverPort: string = await Utility.getPort(serverConfig, Constants.Port.Server); | ||
const httpPort: string = await Utility.getPort(serverConfig, Constants.Port.Http); | ||
const httpsPort: string = await Utility.getPort(serverConfig, Constants.Port.Https); | ||
|
||
try { | ||
if (serverUri) { | ||
|
@@ -260,20 +264,25 @@ export class TomcatController { | |
statusBar.show(); | ||
} | ||
|
||
watcher = chokidar.watch(serverInfo.getServerConfigPath()); | ||
watcher = chokidar.watch(serverConfig); | ||
watcher.on('change', async () => { | ||
const promptString: string = localize('tomcatExt.configChanged', | ||
'server.xml of running server {0} has been changed. Would you like to restart it?', | ||
serverName); | ||
const item: vscode.MessageItem = await vscode.window.showInformationMessage(promptString, DialogMessage.yes, DialogMessage.no); | ||
if (item === DialogMessage.yes) { | ||
try { | ||
// Need restart tomcat | ||
await this.stopServer(serverInfo); | ||
serverInfo.needRestart = true; | ||
} catch (err) { | ||
console.error(err.toString()); | ||
vscode.window.showErrorMessage(localize('tomcatExt.stopFailure', 'Failed to stop Tomcat Server {0}', serverName)); | ||
if (serverPort !== await Utility.getPort(serverConfig, Constants.Port.Server)) { | ||
vscode.window.showErrorMessage(localize('tomcatExt.serverPortChangeError', `Changing the server port of a running server will cause errors, please change it back to ${ serverPort} !`)); | ||
} else if (httpPort !== await Utility.getPort(serverConfig, Constants.Port.Http) || | ||
httpsPort !== await Utility.getPort(serverConfig, Constants.Port.Https)) { | ||
const promptString: string = localize('tomcatExt.configChanged', | ||
'server.xml of running server {0} has been changed. Would you like to restart it?', | ||
serverName); | ||
const item: vscode.MessageItem = await vscode.window.showInformationMessage(promptString, DialogMessage.yes, DialogMessage.no); | ||
if (item === DialogMessage.yes) { | ||
try { | ||
// Need restart tomcat | ||
await this.stopServer(serverInfo); | ||
serverInfo.needRestart = true; | ||
} catch (err) { | ||
console.error(err.toString()); | ||
vscode.window.showErrorMessage(localize('tomcatExt.stopFailure', 'Failed to stop Tomcat Server {0}', serverName)); | ||
} | ||
} | ||
} | ||
}); | ||
|
@@ -283,34 +292,28 @@ export class TomcatController { | |
setTimeout(() => this.setStarted(serverInfo, true), 500); | ||
await javaProcess; | ||
this.setStarted(serverInfo, false); | ||
this.disposeResource(statusBarCommand); | ||
this.disposeResource(statusBar); | ||
this.disposeResources([statusBarCommand, statusBar]); | ||
watcher.close(); | ||
if (serverInfo.needRestart) { | ||
serverInfo.needRestart = false; | ||
await this.startTomcat(serverInfo, appName, output); | ||
} | ||
} catch (err) { | ||
this.setStarted(serverInfo, false); | ||
this.disposeResource(statusBarCommand); | ||
this.disposeResource(statusBar); | ||
this.disposeResources([statusBarCommand, statusBar]); | ||
if (watcher) { watcher.close(); } | ||
throw new Error(err.toString()); | ||
} | ||
} | ||
|
||
private disposeResource(resource: vscode.Disposable | undefined): void { | ||
if (resource) { | ||
resource.dispose(); | ||
private disposeResources(resources: vscode.Disposable[]): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this method only has one argument, how about making it as an open-ended function arguments: private disposeResources(...resources: vscode.Disposable[]) then no need to wrap arguments in |
||
if (resources) { | ||
resources.forEach((item: vscode.Disposable) => item.dispose()); | ||
} | ||
} | ||
|
||
private getChannelName(serverInfo: TomcatServer): string { | ||
return `Tomcat_${serverInfo.getName()}`; | ||
} | ||
|
||
private getOutput(serverInfo: TomcatServer): vscode.OutputChannel { | ||
const channelName: string = this.getChannelName(serverInfo); | ||
const channelName: string = `Tomcat_${serverInfo.getName()}`; | ||
let output: vscode.OutputChannel = this._outputChannels.get(channelName); | ||
if (!output) { | ||
output = vscode.window.createOutputChannel(channelName); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about renaming it to :
PortKind