Skip to content

Commit 7052c6d

Browse files
authored
Merge pull request #255 from jGauravGupta/deploy-with-debug
FISH-13206 Fix "Debug on Server" deployment failure caused by JVM module access error on restart
2 parents 7f7afa4 + 8251f5a commit 7052c6d

2 files changed

Lines changed: 37 additions & 14 deletions

File tree

src/main/fish/payara/server/PayaraServerInstanceController.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
634634
}
635635

636636

637-
public async startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string, callback?: (status: boolean) => any): Promise<void> {
637+
public async startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string | number | undefined, callback?: (status: boolean) => any): Promise<void> {
638638
if (!payaraServer.isStopped()) {
639639
vscode.window.showErrorMessage('Payara Server instance already running.');
640640
return;
@@ -744,6 +744,25 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
744744
});
745745
}
746746

747+
private async stopAndStartInDebugMode(payaraServer: PayaraLocalServerInstance, debugPort: string | number | undefined, callback?: (status: boolean) => any): Promise<void> {
748+
let endpoints: RestEndpoints = new RestEndpoints(payaraServer);
749+
endpoints.invoke("stop-domain", async (_res) => {
750+
payaraServer.setState(InstanceState.STOPPED);
751+
payaraServer.setDebug(false);
752+
await new Promise(resolve => setTimeout(resolve, 2000));
753+
this.refreshServerList();
754+
payaraServer.disconnectOutput();
755+
this.startServer(payaraServer, true, debugPort, callback);
756+
},
757+
(_res, message) => {
758+
vscode.window.showErrorMessage('Unable to stop the Payara Server before restarting in debug mode. ' + message);
759+
if (callback) {
760+
callback(false);
761+
}
762+
}
763+
);
764+
}
765+
747766
public async renameServer(payaraServer: PayaraServerInstance): Promise<void> {
748767
if (payaraServer) {
749768
await vscode.window.showInputBox({
@@ -848,7 +867,7 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
848867
if (server instanceof PayaraLocalServerInstance && !server.isStarted()) {
849868
this.startServer(server, debug, debugPort, deploy);
850869
} else if (server instanceof PayaraLocalServerInstance && debug && !server.isDebug()) {
851-
this.restartServer(server, debug, deploy);
870+
this.stopAndStartInDebugMode(server, debugPort, deploy);
852871
} else {
853872
deploy(true);
854873
}
@@ -1137,4 +1156,4 @@ interface State {
11371156
username: string;
11381157
password: string;
11391158
name: string;
1140-
}
1159+
}

src/main/fish/payara/server/start/StartTask.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { PayaraLocalServerInstance } from "../PayaraLocalServerInstance";
3434

3535
export class StartTask {
3636

37-
public startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string): ChildProcess {
37+
public startServer(payaraServer: PayaraLocalServerInstance, debug: boolean, debugPort: string | number | undefined): ChildProcess {
3838
let jvmConfigReader: JvmConfigReader = new JvmConfigReader(payaraServer.getDomainXmlPath(), ServerUtils.DAS_NAME);
3939

4040
let javaHome: string | undefined = payaraServer.getJDKHome();
@@ -49,12 +49,12 @@ export class StartTask {
4949

5050
for (const jvmOption of jvmConfigReader.getJvmOptions()) {
5151
if (JDKVersion.isCorrectJDK(
52-
javaVersion,
53-
jvmOption.vendor,
54-
jvmOption.minVersion,
55-
jvmOption.maxVersion,
56-
jvmOption.option,
57-
javaHome)) {
52+
javaVersion,
53+
jvmOption.vendor,
54+
jvmOption.minVersion,
55+
jvmOption.maxVersion,
56+
jvmOption.option,
57+
javaHome)) {
5858

5959
optList.push(jvmOption.option);
6060
}
@@ -105,12 +105,16 @@ export class StartTask {
105105
return cp.spawn(javaVmExe, args, { cwd: payaraServer.getPath() });
106106
}
107107

108-
private isValidPort(portStr?: string): boolean {
109-
if (!portStr) {
108+
private isValidPort(portStr?: string | number): boolean {
109+
if (portStr === undefined || portStr === null || portStr === '') {
110110
return false;
111111
}
112-
const port = parseInt(portStr, 10);
113-
return portStr.trim() !== '' && port >= 0 && port <= 65535;
112+
const portString = String(portStr).trim();
113+
if (portString === '') {
114+
return false;
115+
}
116+
const port = parseInt(portString, 10);
117+
return !isNaN(port) && port >= 0 && port <= 65535;
114118
}
115119

116120
private addJavaAgent(payaraServer: PayaraLocalServerInstance, jvmConfigReader: JvmConfigReader): void {

0 commit comments

Comments
 (0)