|
| 1 | +diff --git a/extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NetBeansRunSinglePlugin.java b/extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NetBeansRunSinglePlugin.java |
| 2 | +index e1e01c3aed..0ca4b052be 100644 |
| 3 | +--- a/extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NetBeansRunSinglePlugin.java |
| 4 | ++++ b/extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NetBeansRunSinglePlugin.java |
| 5 | +@@ -19,8 +19,10 @@ |
| 6 | + |
| 7 | + package org.netbeans.modules.gradle.tooling; |
| 8 | + |
| 9 | ++import java.util.Arrays; |
| 10 | + import static java.util.Arrays.asList; |
| 11 | + import java.util.List; |
| 12 | ++import java.util.Objects; |
| 13 | + import java.util.Set; |
| 14 | + import org.gradle.api.DefaultTask; |
| 15 | + import org.gradle.api.logging.Logger; |
| 16 | +@@ -29,7 +31,9 @@ import org.gradle.api.logging.LogLevel; |
| 17 | + import org.gradle.api.Plugin; |
| 18 | + import org.gradle.api.Project; |
| 19 | + import org.gradle.api.Task; |
| 20 | ++import org.gradle.api.file.FileCollection; |
| 21 | + import org.gradle.api.tasks.JavaExec; |
| 22 | ++import org.gradle.api.tasks.SourceSet; |
| 23 | + import org.gradle.api.tasks.SourceSetContainer; |
| 24 | + import org.gradle.api.tasks.TaskProvider; |
| 25 | + import org.gradle.process.CommandLineArgumentProvider; |
| 26 | +@@ -47,6 +51,7 @@ class NetBeansRunSinglePlugin implements Plugin<Project> { |
| 27 | + private static final String RUN_SINGLE_ARGS = "runArgs"; |
| 28 | + private static final String RUN_SINGLE_JVM_ARGS = "runJvmArgs"; |
| 29 | + private static final String RUN_SINGLE_CWD = "runWorkingDir"; |
| 30 | ++ private static final String RUN_SINGLE_SOURCE_SET_NAMES = "runSourceSetNames"; |
| 31 | + |
| 32 | + private static final String DEPRECATE_RUN_SINGLE = |
| 33 | + "runSingle task is deprecated. Inspect your configuration and use just 'run' task instead of 'runSingle'"; |
| 34 | +@@ -64,6 +69,20 @@ class NetBeansRunSinglePlugin implements Plugin<Project> { |
| 35 | + } |
| 36 | + |
| 37 | + private void configureJavaExec(Project project, JavaExec je) { |
| 38 | ++ Object sourceSetValue = project.findProperty(RUN_SINGLE_SOURCE_SET_NAMES); |
| 39 | ++ if (sourceSetValue != null) { |
| 40 | ++ SourceSetContainer sourceSets = project.getExtensions().findByType(SourceSetContainer.class); |
| 41 | ++ if (sourceSets != null) { |
| 42 | ++ FileCollection updatedClasspath = Arrays.stream(sourceSetValue.toString().split(",")) |
| 43 | ++ .map(String::trim) |
| 44 | ++ .map(sourceSets::findByName) |
| 45 | ++ .filter(Objects::nonNull) |
| 46 | ++ .map(SourceSet::getRuntimeClasspath) |
| 47 | ++ .reduce(project.getObjects().fileCollection(), FileCollection::plus); |
| 48 | ++ |
| 49 | ++ je.setClasspath(updatedClasspath); |
| 50 | ++ } |
| 51 | ++ } |
| 52 | + if (project.hasProperty(RUN_SINGLE_MAIN)) { |
| 53 | + String mainClass = project.property(RUN_SINGLE_MAIN).toString(); |
| 54 | + if (GRADLE_VERSION.compareTo(GradleVersion.version("6.4")) < 0) { |
| 55 | +diff --git a/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java b/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java |
| 56 | +index 3718f1f2ed..8736be5755 100644 |
| 57 | +--- a/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java |
| 58 | ++++ b/ide/lsp.client/test/unit/src/org/netbeans/modules/lsp/client/debugger/DebuggerTest.java |
| 59 | +@@ -125,7 +125,8 @@ public class DebuggerTest extends NbTestCase { |
| 60 | + .addConfiguration(Map.of("type", "java+", |
| 61 | + "request", "launch", |
| 62 | + "file", FileUtil.toFile(testFile).getAbsolutePath(), |
| 63 | +- "classPaths", List.of("any"))) |
| 64 | ++ "classPaths", List.of("any"), |
| 65 | ++ "testRun", false)) |
| 66 | + .launch(); |
| 67 | + waitFor(true, () -> DebuggerManager.getDebuggerManager().getSessions().length > 0); |
| 68 | + assertEquals(1, DebuggerManager.getDebuggerManager().getSessions().length); |
| 69 | +@@ -198,7 +199,8 @@ public class DebuggerTest extends NbTestCase { |
| 70 | + .addConfiguration(Map.of("type", "java+", |
| 71 | + "request", "launch", |
| 72 | + "file", FileUtil.toFile(testFile).getAbsolutePath(), |
| 73 | +- "classPaths", List.of("any"))) |
| 74 | ++ "classPaths", List.of("any"), |
| 75 | ++ "testRun", false)) |
| 76 | + .launch(); |
| 77 | + waitFor(true, () -> DebuggerManager.getDebuggerManager().getSessions().length > 0); |
| 78 | + assertEquals(1, DebuggerManager.getDebuggerManager().getSessions().length); |
| 79 | +diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaTokenProvider.java b/java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaTokenProvider.java |
| 80 | +index 84435b7fbc..418f3e603e 100644 |
| 81 | +--- a/java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaTokenProvider.java |
| 82 | ++++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaTokenProvider.java |
| 83 | +@@ -53,12 +53,14 @@ public class GradleJavaTokenProvider implements ReplaceTokenProvider { |
| 84 | + private static final String AFFECTED_BUILD_TASK = "affectedBuildTasks";//NOI18N |
| 85 | + private static final String TEST_TASK_NAME = "testTaskName"; //NOI18N |
| 86 | + private static final String CLEAN_TEST_TASK_NAME = "cleanTestTaskName"; //NOI18N |
| 87 | ++ private static final String SOURCE_SET_NAMES = "sourceSetNames"; //NOI18N |
| 88 | + |
| 89 | + private static final Set<String> SUPPORTED = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList( |
| 90 | + SELECTED_CLASS, |
| 91 | + SELECTED_CLASS_NAME, |
| 92 | + SELECTED_METHOD, |
| 93 | + SELECTED_PACKAGE, |
| 94 | ++ SOURCE_SET_NAMES, |
| 95 | + AFFECTED_BUILD_TASK |
| 96 | + ))); |
| 97 | + |
| 98 | +@@ -123,6 +125,7 @@ public class GradleJavaTokenProvider implements ReplaceTokenProvider { |
| 99 | + GradleJavaSourceSet ss = gjp.containingSourceSet(f); |
| 100 | + if (ss != null) { |
| 101 | + Set<GradleJavaSourceSet.SourceType> types = ss.getSourceTypes(f); |
| 102 | ++ map.merge(SOURCE_SET_NAMES, ss.getName(), (oldVal, newVal) -> oldVal.trim() + "," + newVal.trim()); |
| 103 | + for (GradleJavaSourceSet.SourceType type : types) { |
| 104 | + buildTasks.add(ss.getBuildTaskName(type)); |
| 105 | + } |
| 106 | +diff --git a/java/gradle.java/src/org/netbeans/modules/gradle/java/action-mapping.xml b/java/gradle.java/src/org/netbeans/modules/gradle/java/action-mapping.xml |
| 107 | +index 97fadb9fee..8e27c5699b 100644 |
| 108 | +--- a/java/gradle.java/src/org/netbeans/modules/gradle/java/action-mapping.xml |
| 109 | ++++ b/java/gradle.java/src/org/netbeans/modules/gradle/java/action-mapping.xml |
| 110 | +@@ -53,11 +53,11 @@ |
| 111 | + </action> |
| 112 | + |
| 113 | + <action name="run.single"> |
| 114 | +- <args>-PrunClassName=${selectedClass} ${javaExec.workingDir} ${javaExec.environment} run --stacktrace ${javaExec.jvmArgs} ${javaExec.args}</args> |
| 115 | ++ <args>-PrunClassName=${selectedClass} -PrunSourceSetNames=${sourceSetNames} ${javaExec.workingDir} ${javaExec.environment} run --stacktrace ${javaExec.jvmArgs} ${javaExec.args}</args> |
| 116 | + </action> |
| 117 | + |
| 118 | + <action name="debug.single"> |
| 119 | +- <args>-PrunClassName=${selectedClass} ${javaExec.workingDir} ${javaExec.environment} run --stacktrace --debug-jvm ${javaExec.jvmArgs} ${javaExec.args}</args> |
| 120 | ++ <args>-PrunClassName=${selectedClass} -PrunSourceSetNames=${sourceSetNames} ${javaExec.workingDir} ${javaExec.environment} run --stacktrace --debug-jvm ${javaExec.jvmArgs} ${javaExec.args}</args> |
| 121 | + </action> |
| 122 | + </apply-for> |
| 123 | + |
| 124 | +@@ -91,7 +91,7 @@ |
| 125 | + <actions> |
| 126 | + <apply-for plugins="java"> |
| 127 | + <action name="run.single"> |
| 128 | +- <args>-PrunClassName=${selectedClass} ${javaExec.workingDir} ${javaExec.environment} run --continuous ${javaExec.jvmArgs} ${javaExec.args}</args> |
| 129 | ++ <args>-PrunClassName=${selectedClass} -PrunSourceSetNames=${sourceSetNames} ${javaExec.workingDir} ${javaExec.environment} run --continuous ${javaExec.jvmArgs} ${javaExec.args}</args> |
| 130 | + </action> |
| 131 | + <action name="test.single"> |
| 132 | + <args>"${cleanTestTaskName}" "${testTaskName}" --tests "${selectedClass}" --continuous</args> |
| 133 | +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 |
| 134 | +index e503da42bd..93cbc81339 100644 |
| 135 | +--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java |
| 136 | ++++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java |
| 137 | +@@ -28,6 +28,7 @@ import java.util.Arrays; |
| 138 | + import java.util.Collection; |
| 139 | + import java.util.Collections; |
| 140 | + import java.util.List; |
| 141 | ++import java.util.Locale; |
| 142 | + import java.util.Map; |
| 143 | + import java.util.Objects; |
| 144 | + import java.util.Optional; |
| 145 | +@@ -60,6 +61,8 @@ import org.netbeans.api.extexecution.ExecutionDescriptor; |
| 146 | + import org.netbeans.api.extexecution.ExecutionService; |
| 147 | + import org.netbeans.api.java.classpath.ClassPath; |
| 148 | + import org.netbeans.api.java.queries.UnitTestForSourceQuery; |
| 149 | ++import org.netbeans.api.java.source.ClasspathInfo; |
| 150 | ++import org.netbeans.api.java.source.SourceUtils; |
| 151 | + import org.netbeans.api.project.FileOwnerQuery; |
| 152 | + import org.netbeans.api.project.Project; |
| 153 | + import org.netbeans.api.project.ProjectUtils; |
| 154 | +@@ -84,6 +87,7 @@ import org.netbeans.spi.project.ProjectConfigurationProvider; |
| 155 | + import org.netbeans.spi.project.SingleMethod; |
| 156 | + |
| 157 | + import org.openide.filesystems.FileObject; |
| 158 | ++import org.openide.filesystems.FileUtil; |
| 159 | + import org.openide.util.BaseUtilities; |
| 160 | + import org.openide.util.Lookup; |
| 161 | + import org.openide.util.NbBundle; |
| 162 | +@@ -114,6 +118,7 @@ public abstract class NbLaunchDelegate { |
| 163 | + |
| 164 | + private final RequestProcessor requestProcessor = new RequestProcessor(NbLaunchDelegate.class); |
| 165 | + private final Map<DebugAdapterContext, DebuggerManagerListener> debuggerListeners = new ConcurrentHashMap<>(); |
| 166 | ++ private final static String JAVA_FILE_EXT = ".java"; |
| 167 | + |
| 168 | + public abstract void preLaunch(Map<String, Object> launchArguments, DebugAdapterContext context); |
| 169 | + |
| 170 | +@@ -570,8 +575,20 @@ public abstract class NbLaunchDelegate { |
| 171 | + } else if (launchType == LaunchType.RUN_TEST) { |
| 172 | + mainSource = false; |
| 173 | + } else { |
| 174 | +- FileObject fileRoot = sourceCP != null ? sourceCP.findOwnerRoot(toRun) : null; |
| 175 | +- mainSource = fileRoot == null || UnitTestForSourceQuery.findSources(fileRoot).length == 0; |
| 176 | ++ mainSource = true; |
| 177 | ++ if (sourceCP != null) { |
| 178 | ++ FileObject root = sourceCP.findOwnerRoot(toRun); |
| 179 | ++ if (root != null) { |
| 180 | ++ if (UnitTestForSourceQuery.findSources(root).length > 0) { |
| 181 | ++ String relativePath = FileUtil.getRelativePath(root, toRun); |
| 182 | ++ if (relativePath != null && relativePath.toLowerCase(Locale.ENGLISH).endsWith(JAVA_FILE_EXT)) { |
| 183 | ++ String className = relativePath.substring(0, relativePath.length() - JAVA_FILE_EXT.length()).replace('/', '.'); |
| 184 | ++ ClasspathInfo cpi = ClasspathInfo.create(toRun); |
| 185 | ++ mainSource = SourceUtils.isMainClass(className, cpi, true); |
| 186 | ++ } |
| 187 | ++ } |
| 188 | ++ } |
| 189 | ++ } |
| 190 | + } |
| 191 | + ActionProvider provider = null; |
| 192 | + String command = null; |
0 commit comments