Skip to content

Commit b00e378

Browse files
committed
FISH-7541 Open the server home and domain directory in Explorer via VS Code
1 parent f91169e commit b00e378

5 files changed

Lines changed: 131 additions & 26 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ yarn.lock
55
package-lock.json
66
*.vsix
77
.vscode-test/
8+
yarn-error.log

package.json

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"onCommand:payara.server.console.open",
4242
"onCommand:payara.server.log.open",
4343
"onCommand:payara.server.config.open",
44+
"onCommand:payara.server.domain.open",
45+
"onCommand:payara.server.home.open",
4446
"onCommand:payara.server.app.deploy",
4547
"onCommand:payara.server.app.debug",
4648
"onCommand:payara.server.app.migrate",
@@ -174,6 +176,16 @@
174176
"title": "View Domain Server Config",
175177
"category": "Payara"
176178
},
179+
{
180+
"command": "payara.server.domain.open",
181+
"title": "Open Domain Directory",
182+
"category": "Payara"
183+
},
184+
{
185+
"command": "payara.server.home.open",
186+
"title": "Open Server Home Directory",
187+
"category": "Payara"
188+
},
177189
{
178190
"command": "payara.server.app.deploy",
179191
"title": "Run on Payara Server",
@@ -409,6 +421,14 @@
409421
"command": "payara.server.config.open",
410422
"when": "never"
411423
},
424+
{
425+
"command": "payara.server.domain.open",
426+
"when": "never"
427+
},
428+
{
429+
"command": "payara.server.home.open",
430+
"when": "never"
431+
},
412432
{
413433
"command": "payara.server.app.deploy",
414434
"when": "never"
@@ -578,6 +598,16 @@
578598
"when": "viewItem == loadingPayaraLocal || viewItem == runningPayaraLocal || viewItem == stoppedPayaraLocal",
579599
"group": "view@11"
580600
},
601+
{
602+
"command": "payara.server.domain.open",
603+
"when": "viewItem == loadingPayaraLocal || viewItem == runningPayaraLocal || viewItem == stoppedPayaraLocal",
604+
"group": "view@12"
605+
},
606+
{
607+
"command": "payara.server.home.open",
608+
"when": "viewItem == loadingPayaraLocal || viewItem == runningPayaraLocal || viewItem == stoppedPayaraLocal",
609+
"group": "view@13"
610+
},
581611
{
582612
"command": "payara.server.app.undeploy",
583613
"when": "viewItem == payara-application",
@@ -694,7 +724,7 @@
694724
"fs-extra": "^11.1.0",
695725
"gradle-to-js": "^2.0.0",
696726
"lodash": "^4.17.21",
697-
"open": "^9.1.0 ",
727+
"open": "^8.4.2 ",
698728
"request": "^2.88.0",
699729
"tail": "^2.0.3",
700730
"tmp": "^0.2.0",
@@ -708,7 +738,7 @@
708738
"@types/mocha": "^10.0.0",
709739
"@types/node": "^20.3.1",
710740
"@types/vscode": "^1.22.0",
711-
"glob": "^10.2.7",
741+
"glob": "^7.1.7",
712742
"mocha": "^10.0.0",
713743
"os": "^0.1.1",
714744
"tslint": "^6.1.0",

src/main/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
187187
payaraServer => payaraServerInstanceController.openConfig(payaraServer)
188188
)
189189
);
190+
context.subscriptions.push(
191+
vscode.commands.registerCommand(
192+
'payara.server.domain.open',
193+
payaraServer => payaraServerInstanceController.openDomainDirectory(payaraServer)
194+
)
195+
);
196+
context.subscriptions.push(
197+
vscode.commands.registerCommand(
198+
'payara.server.home.open',
199+
payaraServer => payaraServerInstanceController.openServerHomeDirectory(payaraServer)
200+
)
201+
);
190202
context.subscriptions.push(
191203
vscode.commands.registerCommand(
192204
'payara.server.app.deploy',

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,16 @@ export class PayaraServerInstanceController extends PayaraInstanceController {
801801
.then(doc => vscode.window.showTextDocument(doc));
802802
}
803803

804+
public async openDomainDirectory(payaraServer: PayaraLocalServerInstance): Promise<void> {
805+
let domainDirectory = Uri.file(payaraServer.getDomainPath());
806+
vscode.env.openExternal(domainDirectory);
807+
}
808+
809+
public async openServerHomeDirectory(payaraServer: PayaraLocalServerInstance): Promise<void> {
810+
let serverHomeDirectory = Uri.file(payaraServer.getServerHome());
811+
vscode.env.openExternal(serverHomeDirectory);
812+
}
813+
804814
public async refreshServerList(): Promise<void> {
805815
vscode.commands.executeCommand('payara.server.refresh');
806816
}

src/test/suite/index.ts

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as path from 'path';
22
import * as Mocha from 'mocha';
33
import * as glob from 'glob';
4+
import * as fs from 'fs';
45

5-
export function run(): Promise<void> {
6+
export async function run(): Promise<void> {
67
// Create the mocha test
78
const mocha = new Mocha({
89
ui: 'tdd',
@@ -11,27 +12,78 @@ export function run(): Promise<void> {
1112

1213
const testsRoot = path.resolve(__dirname, '..');
1314

14-
return new Promise((c, e) => {
15-
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
16-
if (err) {
17-
return e(err);
18-
}
19-
20-
// Add files to the test suite
21-
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
22-
23-
try {
24-
// Run the mocha test
25-
mocha.run(failures => {
26-
if (failures > 0) {
27-
e(new Error(`${failures} tests failed.`));
28-
} else {
29-
c();
30-
}
31-
});
32-
} catch (err) {
33-
e(err);
34-
}
35-
});
36-
});
15+
// // Add test files to the Mocha instance
16+
// const testFiles = await getTestFiles(testsRoot);
17+
// testFiles.forEach((file) => {
18+
// mocha.addFile(file);
19+
// });
20+
21+
// Detect test files and add them to Mocha
22+
const testFiles = findTestFiles(testsRoot);
23+
testFiles.forEach((file: string) => {
24+
mocha.addFile(file);
25+
});
26+
27+
// Run the tests
28+
try {
29+
await new Promise<void>((resolve, reject) => {
30+
mocha.run((failures) => {
31+
if (failures > 0) {
32+
reject(new Error(`${failures} tests failed.`));
33+
} else {
34+
resolve();
35+
}
36+
});
37+
});
38+
} catch (error) {
39+
console.error('Failed to run tests:', error);
40+
process.exit(1);
41+
}
42+
43+
// return new Promise((c, e) => {
44+
// glob('**/**.test.js', { cwd: testsRoot }, (err: any, files: string[]) => {
45+
// if (err) {
46+
// return e(err);
47+
// }
48+
49+
// // Add files to the test suite
50+
// files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
51+
52+
// try {
53+
// // Run the mocha test
54+
// mocha.run((failures: number) => {
55+
// if (failures > 0) {
56+
// e(new Error(`${failures} tests failed.`));
57+
// } else {
58+
// c();
59+
// }
60+
// });
61+
// } catch (err) {
62+
// e(err);
63+
// }
64+
// });
65+
// });
66+
}
67+
68+
function findTestFiles(rootDir: string): string[] {
69+
const testFiles: string[] = [];
70+
const files = fs.readdirSync(rootDir);
71+
72+
files.forEach((file: string) => {
73+
const filePath = path.join(rootDir, file);
74+
const stats = fs.statSync(filePath);
75+
76+
if (stats.isDirectory()) {
77+
testFiles.push(...findTestFiles(filePath));
78+
} else if (file.endsWith('.test.js')) { // Adjust the file extension if needed
79+
testFiles.push(filePath);
80+
}
81+
});
82+
83+
return testFiles;
84+
}
85+
86+
// Run the tests when the script is executed directly
87+
if (require.main === module) {
88+
run();
3789
}

0 commit comments

Comments
 (0)