Skip to content

Commit 30490b4

Browse files
chore: feedback!
1 parent 41ac4eb commit 30490b4

3 files changed

Lines changed: 105 additions & 8 deletions

File tree

package.nls.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"java.debugger.launch.modulePaths.auto": "Automatically resolve the module paths of current project.",
99
"java.debugger.launch.modulePaths.runtime": "The module paths within 'runtime' scope of current project.",
1010
"java.debugger.launch.modulePaths.test": "The module paths within 'test' scope of current project.",
11-
"java.debugger.launch.modulePaths.exclude": "The path after '!' will be excluded from the modulePaths.",
11+
"java.debugger.launch.modulePaths.exclude": "The path after '!' will be excluded from the modulePaths. A slash (forwards or backwards) will treat the path as an exact match.",
1212
"java.debugger.launch.classPaths.description": "The classpaths for launching the JVM. If not specified, the debugger will automatically resolve from current project.",
1313
"java.debugger.launch.classPaths.auto": "Automatically resolve the classpaths of current project.",
1414
"java.debugger.launch.classPaths.runtime": "The classpaths within 'runtime' scope of current project.",
1515
"java.debugger.launch.classPaths.test": "The classpaths within 'test' scope of current project.",
16-
"java.debugger.launch.classPaths.exclude": "The path after '!' will be excluded from the classpaths.",
16+
"java.debugger.launch.classPaths.exclude": "The path after '!' will be excluded from the classpaths. A slash (forwards or backwards) will treat the path as an exact match.",
1717
"java.debugger.launch.sourcePaths.description": "The extra source directories of the program. The debugger looks for source code from project settings by default. This option allows the debugger to look for source code in extra directories.",
1818
"java.debugger.launch.encoding.description": "The file.encoding setting for the JVM. Possible values can be found in https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html.",
1919
"java.debugger.launch.cwd.description": "The working directory of the program. Defaults to the current workspace root.",

src/configurationProvider.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,19 +490,20 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
490490
const excludes: Map<string, boolean> = new Map<string, boolean>();
491491
for (const p of paths) {
492492
if (p.startsWith("!")) {
493-
let exclude = p.substr(1);
493+
let exclude = p.slice(1);
494494
let isDirect: boolean;
495-
if (!path.isAbsolute(exclude)) {
496-
exclude = path.join(folder?.uri.fsPath || "", exclude);
497-
}
498495

499-
if (exclude.endsWith(process.platform === 'win32' ? '\\' : '/')) {
500-
exclude = exclude.substr(0, exclude.length - 1);
496+
if (/[\\/]$/.test(exclude)) {
497+
exclude = exclude.slice(0, -1);
501498
isDirect = true;
502499
} else {
503500
isDirect = this.isFilePath(exclude);
504501
}
505502

503+
if (!path.isAbsolute(exclude)) {
504+
exclude = path.join(folder?.uri.fsPath || "", exclude);
505+
}
506+
506507
// use Uri to normalize the fs path
507508
excludes.set(vscode.Uri.file(exclude).fsPath, isDirect);
508509
continue;

test/configurationProvider.test.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import * as assert from "assert";
5+
import * as fs from "fs";
6+
import * as os from "os";
7+
import * as path from "path";
8+
import * as vscode from "vscode";
9+
10+
import { JavaDebugConfigurationProvider } from "../src/configurationProvider";
11+
12+
interface TestWorkspace {
13+
root: string;
14+
folder: vscode.WorkspaceFolder;
15+
libDir: string;
16+
jarPath: string;
17+
}
18+
19+
type FilterExcluded = (
20+
folder: vscode.WorkspaceFolder | undefined,
21+
paths: string[],
22+
) => Promise<string[]>;
23+
24+
function createTestWorkspace(): TestWorkspace {
25+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "java-debug-cp-test-"));
26+
const libDir = path.join(root, "lib");
27+
fs.mkdirSync(libDir);
28+
const jarPath = path.join(libDir, "foo.jar");
29+
fs.writeFileSync(jarPath, "");
30+
return {
31+
root,
32+
folder: {
33+
uri: vscode.Uri.file(root),
34+
name: "test-workspace",
35+
index: 0,
36+
},
37+
libDir,
38+
jarPath,
39+
};
40+
}
41+
42+
function getFilterExcluded(provider: JavaDebugConfigurationProvider): FilterExcluded {
43+
return (provider as unknown as { filterExcluded: FilterExcluded }).filterExcluded.bind(provider);
44+
}
45+
46+
suite("JavaDebugConfigurationProvider", () => {
47+
const workspaces: TestWorkspace[] = [];
48+
49+
suiteSetup(() => {
50+
// configurationProvider requires ../package.json relative to out/src/
51+
const outPackageJson = path.join(__dirname, "../package.json");
52+
if (!fs.existsSync(outPackageJson)) {
53+
fs.copyFileSync(path.join(__dirname, "../../package.json"), outPackageJson);
54+
}
55+
});
56+
57+
teardown(() => {
58+
while (workspaces.length > 0) {
59+
const workspace = workspaces.pop()!;
60+
fs.rmSync(workspace.root, { recursive: true, force: true });
61+
}
62+
});
63+
64+
suite("filterExcluded exact-match exclusions", () => {
65+
async function assertExactDirectoryExclusion(
66+
excludeSuffix: "\\" | "/",
67+
label: string,
68+
): Promise<void> {
69+
const workspace = createTestWorkspace();
70+
workspaces.push(workspace);
71+
72+
const libDirFs = vscode.Uri.file(workspace.libDir).fsPath;
73+
const jarFs = vscode.Uri.file(workspace.jarPath).fsPath;
74+
const filterExcluded = getFilterExcluded(new JavaDebugConfigurationProvider());
75+
const result = await filterExcluded(workspace.folder, [
76+
libDirFs,
77+
jarFs,
78+
`!${workspace.libDir}${excludeSuffix}`,
79+
]);
80+
81+
assert.deepStrictEqual(
82+
result,
83+
[jarFs],
84+
`${label}: trailing slash should exact-exclude only the directory entry, not paths beneath it`,
85+
);
86+
}
87+
88+
test("treats a trailing backslash as an exact match (Windows-style paths)", async () => {
89+
await assertExactDirectoryExclusion("\\", "Windows-style");
90+
});
91+
92+
test("treats a trailing forward slash as an exact match (Linux-style paths)", async () => {
93+
await assertExactDirectoryExclusion("/", "Linux-style");
94+
});
95+
});
96+
});

0 commit comments

Comments
 (0)