Skip to content

Ignore @SpringBootApplication classes in test source folders - #421

Open
Martin Lippert (martinlippert) wants to merge 1 commit into
microsoft:mainfrom
martinlippert:gh-420-ignore-test-main-classes
Open

Ignore @SpringBootApplication classes in test source folders#421
Martin Lippert (martinlippert) wants to merge 1 commit into
microsoft:mainfrom
martinlippert:gh-420-ignore-test-main-classes

Conversation

@martinlippert

Copy link
Copy Markdown
Collaborator

vscode.java.resolveMainClass searches every source folder of a project, so a @SpringBootApplication class copied into src/test/java — a common pattern for integration tests — was offered as an additional launch candidate. Running an app then popped up a quick pick asking the user to choose between the real main class and one that is irrelevant to launch.

Filter those out by matching each resolved main class against the test source folders of the project's classpath. The Spring Tools classpath listener already reports isTest for each source entry (set from IClasspathEntry.isTest()), so no extra language server round trip is needed; the flag was just missing from the CPE type declaration.

The unfiltered list stays available via getMainClasses() so that live processes launched from a test main class are still associated with their app. When every main class sits in a test source folder, the filter falls back to the full list to keep such a project launchable.

Closes #420

`vscode.java.resolveMainClass` searches every source folder of a project,
so a `@SpringBootApplication` class copied into `src/test/java` — a common
pattern for integration tests — was offered as an additional launch
candidate. Running an app then popped up a quick pick asking the user to
choose between the real main class and one that is irrelevant to launch.

Filter those out by matching each resolved main class against the test
source folders of the project's classpath. The Spring Tools classpath
listener already reports `isTest` for each source entry (set from
`IClasspathEntry.isTest()`), so no extra language server round trip is
needed; the flag was just missing from the `CPE` type declaration.

The unfiltered list stays available via `getMainClasses()` so that live
processes launched from a test main class are still associated with their
app. When every main class sits in a test source folder, the filter falls
back to the full list to keep such a project launchable.

Closes microsoft#420
@martinlippert

Copy link
Copy Markdown
Collaborator Author

@microsoft-github-policy-service agree company="Broadcom"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong multiple choices of SpringBootApplication

1 participant