Skip to content

Commit 048af5b

Browse files
authored
Merge pull request #468 from Achal1607/fixed-launch-json
Fix launch.json behavior and hanging issue with multiple main classes
2 parents d03d253 + f63b7d7 commit 048af5b

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,7 @@ The extension will analyze the content of the opened workspace, and relevant oth
200200
1. Check the `pom.xml` file for any duplicated tags.
201201
2. If duplicated tags are found, remove the extra tags and attempt to compile again.
202202
3. Add the `--enable-preview` VM argument to the *exec-maven-plugin* or *maven-surefile-plugin* configurations if they are used execution or test runs.
203-
2. If the "*Launch Java App*" configuration is being used to *Run and Debug* an application, the following issues may occur if no `mainClass` field value is defined.
204-
- Issues:
205-
1. If more than 2 main classes are present in the project, then using the *Run and Debug* button does not launch execution and appears as stuck prior to run.
206-
2. If the editor window open is a file that is not within the src root of the maven/gradle project, then using the *Run and Debug* button launches the projects tests.
207-
- Resolution or Workaround:
208-
1. Open the `launch.json` file.
209-
2. Edit the configuration for the "*Launch Java App*", i.e. the one which has `"type": "jdk"` and `"request": "launch"`.
210-
3. Define a value for the *mainClass* field, i.e. `"mainClass": "<main class fully-qualified-name or file-path>"`.
211-
3. The *Project: Test Project* command executes the project's tests but does not update the Testing or the Tests Results panels. The test output is present only in the Terminal or Debug Console panel.
203+
2. The *Project: Test Project* command executes the project's tests but does not update the Testing or the Tests Results panels. The test output is present only in the Terminal or Debug Console panel.
212204

213205
## Telemetry
214206

build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
patches/8038-draft.diff
5252
patches/8690.diff
5353
patches/8829.diff
54+
patches/8828.diff
5455
patches/7893-draft.diff
5556
patches/8460-draft.diff
5657
patches/8745-draft.diff

patches/8828.diff

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
2+
index a8ca4f2143de..e503da42bd4b 100644
3+
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
4+
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java
5+
@@ -571,7 +571,7 @@ public void finished(boolean success) {
6+
mainSource = false;
7+
} else {
8+
FileObject fileRoot = sourceCP != null ? sourceCP.findOwnerRoot(toRun) : null;
9+
- mainSource = fileRoot != null && UnitTestForSourceQuery.findUnitTests(fileRoot).length > 0;
10+
+ mainSource = fileRoot == null || UnitTestForSourceQuery.findSources(fileRoot).length == 0;
11+
}
12+
ActionProvider provider = null;
13+
String command = null;
14+
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchRequestHandler.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchRequestHandler.java
15+
index b1a472ce99a4..5e6242c6e89d 100644
16+
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchRequestHandler.java
17+
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchRequestHandler.java
18+
@@ -32,6 +32,8 @@
19+
import java.util.concurrent.CompletableFuture;
20+
import java.util.concurrent.atomic.AtomicReference;
21+
import java.util.function.Consumer;
22+
+import java.util.logging.Level;
23+
+import java.util.logging.Logger;
24+
import java.util.regex.Matcher;
25+
import java.util.regex.Pattern;
26+
import java.util.stream.Collectors;
27+
@@ -70,7 +72,7 @@
28+
* @author martin
29+
*/
30+
public final class NbLaunchRequestHandler {
31+
-
32+
+ private static final Logger LOG = Logger.getLogger(NbLaunchRequestHandler.class.getName());
33+
private NbLaunchDelegate activeLaunchHandler;
34+
35+
public CompletableFuture<Void> launch(Map<String, Object> launchArguments, DebugAdapterContext context) {
36+
@@ -148,7 +150,10 @@ public CompletableFuture<Void> launch(Map<String, Object> launchArguments, Debug
37+
case 1:
38+
handleSelectedMainClass.accept(mainClasses.get(0));
39+
break;
40+
- case 2:
41+
+ default:
42+
+ if(mainClasses.size() > 10){
43+
+ LOG.log(Level.WARNING, "The number of main classes is large :{0}", mainClasses.size());
44+
+ }
45+
List<NotifyDescriptor.QuickPick.Item> mainClassItems =
46+
mainClasses.stream()
47+
.map(eh -> new Item(eh.getQualifiedName(), eh.getQualifiedName()))

0 commit comments

Comments
 (0)