sdedic commented on code in PR #8897:
URL: https://github.com/apache/netbeans/pull/8897#discussion_r2422572528
##########
java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaTokenProvider.java:
##########
@@ -123,6 +125,7 @@ private void processSourceSets(final Map<String, String>
map, Lookup context) {
GradleJavaSourceSet ss = gjp.containingSourceSet(f);
if (ss != null) {
Set<GradleJavaSourceSet.SourceType> types =
ss.getSourceTypes(f);
+ map.merge(SOURCE_SET_NAME, ss.getName(), (oldVal, newVal)
-> oldVal + "," + newVal);
Review Comment:
I'd add `trim()` to the values.
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java:
##########
@@ -570,8 +572,18 @@ public void finished(boolean success) {
} else if (launchType == LaunchType.RUN_TEST) {
mainSource = false;
} else {
- FileObject fileRoot = sourceCP != null ?
sourceCP.findOwnerRoot(toRun) : null;
- mainSource = fileRoot == null ||
UnitTestForSourceQuery.findSources(fileRoot).length == 0;
+ mainSource = false;
+ if (sourceCP != null) {
Review Comment:
Corner case here gets result slightly different the previous version:
formerly, if `sourceCP == null` -> `fileRoot == null` -> `mainSouce := true`.
Now `sourceCP == null` -> `mainSource := false`.
OK ?
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NetBeansRunSinglePlugin.java:
##########
@@ -64,6 +69,20 @@ public void apply(Project project) {
}
private void configureJavaExec(Project project, JavaExec je) {
+ Object sourceSetValue =
project.findProperty(RUN_SINGLE_SOURCE_SET_NAME);
+ if (sourceSetValue != null) {
+ SourceSetContainer sourceSets =
project.getExtensions().findByType(SourceSetContainer.class);
+ if (sourceSets != null) {
+ FileCollection additionalClassPath =
Arrays.stream(sourceSetValue.toString().split(","))
+ .map(String::trim)
+ .map(sourceSets::findByName)
+ .filter(Objects::nonNull)
+ .map(SourceSet::getRuntimeClasspath)
+ .reduce(project.getObjects().fileCollection(),
FileCollection::plus);
+
+ je.setClasspath(je.getClasspath().plus(additionalClassPath));
Review Comment:
While this allows running the desired class (as its code is put into the
classpath), it may retain extra items in the classpath. In theory sourcesset's
classpath is one of the dependency configurations, which themselves inherit
from each other. So it may be more correct to **replace** `je.classpath` with
the sourceset's one.
I did not verify it at runtime, though.
##########
extide/gradle/netbeans-gradle-tooling/src/main/java/org/netbeans/modules/gradle/tooling/NetBeansRunSinglePlugin.java:
##########
@@ -47,6 +51,7 @@ class NetBeansRunSinglePlugin implements Plugin<Project> {
private static final String RUN_SINGLE_ARGS = "runArgs";
private static final String RUN_SINGLE_JVM_ARGS = "runJvmArgs";
private static final String RUN_SINGLE_CWD = "runWorkingDir";
+ private static final String RUN_SINGLE_SOURCE_SET_NAME =
"runSourceSetName";
Review Comment:
Nitpick: make plural to suggest multiple names can be used.
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java:
##########
@@ -570,8 +572,18 @@ public void finished(boolean success) {
} else if (launchType == LaunchType.RUN_TEST) {
mainSource = false;
} else {
- FileObject fileRoot = sourceCP != null ?
sourceCP.findOwnerRoot(toRun) : null;
- mainSource = fileRoot == null ||
UnitTestForSourceQuery.findSources(fileRoot).length == 0;
+ mainSource = false;
+ if (sourceCP != null) {
+ FileObject root = sourceCP.findOwnerRoot(toRun);
+ if (root != null) {
+ String relativePath = FileUtil.getRelativePath(root,
toRun);
+ if (relativePath != null &&
relativePath.toLowerCase().endsWith(".java")) {
+ String className = relativePath.substring(0,
relativePath.length() - 5).replace('/', '.');
+ ClasspathInfo cpi = ClasspathInfo.create(toRun);
+ mainSource = SourceUtils.isMainClass(className, cpi,
true);
Review Comment:
Q: can be `cpi` ever null, if there's a sourceCP for `toRun` ?
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java:
##########
@@ -570,8 +572,18 @@ public void finished(boolean success) {
} else if (launchType == LaunchType.RUN_TEST) {
mainSource = false;
} else {
- FileObject fileRoot = sourceCP != null ?
sourceCP.findOwnerRoot(toRun) : null;
- mainSource = fileRoot == null ||
UnitTestForSourceQuery.findSources(fileRoot).length == 0;
+ mainSource = false;
+ if (sourceCP != null) {
+ FileObject root = sourceCP.findOwnerRoot(toRun);
+ if (root != null) {
+ String relativePath = FileUtil.getRelativePath(root,
toRun);
+ if (relativePath != null &&
relativePath.toLowerCase().endsWith(".java")) {
Review Comment:
Nitpick: consider to use a constant for this and its .length() for the
substring end. Maybe use `toLowerCase(Locale.ENGLISH)`.
##########
java/gradle.java/src/org/netbeans/modules/gradle/java/GradleJavaTokenProvider.java:
##########
@@ -53,12 +53,14 @@ public class GradleJavaTokenProvider implements
ReplaceTokenProvider {
private static final String AFFECTED_BUILD_TASK =
"affectedBuildTasks";//NOI18N
private static final String TEST_TASK_NAME = "testTaskName";
//NOI18N
private static final String CLEAN_TEST_TASK_NAME = "cleanTestTaskName";
//NOI18N
+ private static final String SOURCE_SET_NAME = "sourceSetName";
//NOI18N
private static final Set<String> SUPPORTED =
Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
SELECTED_CLASS,
SELECTED_CLASS_NAME,
SELECTED_METHOD,
SELECTED_PACKAGE,
+ SOURCE_SET_NAME,
Review Comment:
Nitpick: make plural to suggest multiple values CAN be used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists