sdedic commented on code in PR #7979: URL: https://github.com/apache/netbeans/pull/7979#discussion_r1889758592
########## ide/projectapi/src/org/netbeans/spi/project/NestedClass.java: ########## @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.spi.project; + +import java.util.Objects; +import org.openide.filesystems.FileObject; + +/** + * Structure representing an identification of a nested class in a file. + * + * <p> + * <code>NestedClass</code> can be used to represent nested classes within parent class + * Example: + * If we have following structure: ParentClass (parent-of) ChildClass1 (parent-of) ChildClass2, + * for ChildClass1 className field would contain "ChildClass1", and + * for ChildClass2 className field would contain "ChildClass1$ChildClass2" + * </p> + * + * @author Dusan Petrovic + * + * @since 1.99 + */ +public final class NestedClass { + + private FileObject file; Review Comment: Make this `final` to be thread-safe. ########## ide/projectapi/src/org/netbeans/spi/project/SingleMethod.java: ########## @@ -53,6 +54,37 @@ public SingleMethod(FileObject file, String methodName) { this.file = file; this.methodName = methodName; } + + /** + * Creates a new instance holding the specified identification + * of a method/function in nested class in a file. + * + * @param file file to be kept in the object + * @param methodName name of a method inside the file + * @param nestedClass nested class containing the method + * + * @exception java.lang.IllegalArgumentException + * if the nested class name is {@code null} + * @since 1.99 + */ + public SingleMethod(FileObject file, String methodName, NestedClass nestedClass) { Review Comment: I'd take the `file` from `NestedClass`. ########## java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/WorkspaceServiceImpl.java: ########## @@ -401,11 +403,15 @@ public CompletableFuture<Object> executeCommand(ExecuteCommandParams params) { LOG.log(Level.INFO, "Project {2}: {0} test roots opened in {1}ms", new Object[] { testRoots.size(), (System.currentTimeMillis() - t), file}); BiFunction<FileObject, Collection<TestMethodController.TestMethod>, Collection<TestSuiteInfo>> f = (fo, methods) -> { String url = Utils.toUri(fo); + Project owner = FileOwnerQuery.getOwner(fo); + String moduleName = owner != null ? ProjectUtils.getInformation(owner).getDisplayName(): null; Review Comment: Careful here. Check with customized gradle and maven project (display) names (different from artfiact names) that it works well. ########## ide/projectapi/src/org/netbeans/spi/project/SingleMethod.java: ########## @@ -94,14 +126,15 @@ public boolean equals(Object obj) { return false; } SingleMethod other = (SingleMethod) obj; - return other.file.equals(file) && other.methodName.equals(methodName); + return other.file.equals(file) && other.methodName.equals(methodName) && other.nestedClass.equals(nestedClass); } @Override public int hashCode() { int hash = 7; hash = 29 * hash + this.file.hashCode(); hash = 29 * hash + this.methodName.hashCode(); + hash = 29 * hash + this.nestedClass.hashCode(); Review Comment: :warning: Objects.hashCode() to avoid NPE on nestedClass; similar for equals. Unlike the other fields, nestedclass is optional. ########## ide/projectapi/src/org/netbeans/spi/project/SingleMethod.java: ########## @@ -31,6 +31,7 @@ public final class SingleMethod { private FileObject file; private String methodName; + private NestedClass nestedClass; Review Comment: maybe final, as well as the other fields. ########## java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/debugging/launch/NbLaunchDelegate.java: ########## @@ -632,11 +656,27 @@ static Lookup createTargetLookup(Project prj, SingleMethod singleMethod, FileObj Lookup methodLookup = Lookups.singleton(singleMethod); arr.add(methodLookup); } + if (nestedClass != null) { + Lookup nestedClassLookup = Lookups.singleton(nestedClass); + arr.add(nestedClassLookup); + } + if (projectFilter != null) { + Lookup projectLookup = Lookups.singleton(projectFilter); + arr.add(projectLookup); + } if (toRun != null) { arr.add(toRun.getLookup()); } return new ProxyLookup(arr.toArray(new Lookup[0])); } + + static ContainedProjectFilter getProjectFilter(Project prj, Map<String, Object> launchArguments) { + List<String> projectsArg = argsToStringList(launchArguments.get("projects")); + List<Project> projects = ProjectUtils.getContainedProjects(prj, false).stream() Review Comment: Note: this does not allow to specify projects nested more levels in the project's hierarchy. Not a bug, and can be enhanced later in a compatible way. ########## java/java.lsp.server/vscode/src/testAdapter.ts: ########## @@ -63,53 +87,122 @@ export class NbTestAdapter { for (let item of include) { if (item.uri) { this.set(item, 'enqueued'); + item.parent?.children.forEach(child => { + if (child.id?.includes(item.id)) { + this.set(child, 'enqueued'); + } + }) const idx = item.id.indexOf(':'); + const nestedClassIdx = item.id.indexOf('$'); + let nestedClass: string | undefined; + if (nestedClassIdx > 0) { + nestedClass = idx < 0 + ? item.id.slice(nestedClassIdx + 1) + : item.id.substring(nestedClassIdx + 1, idx); + } if (!cancellation.isCancellationRequested) { - await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1)); + await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1), nestedClass); } } } } else { this.testController.items.forEach(item => this.set(item, 'enqueued')); for (let workspaceFolder of workspace.workspaceFolders || []) { if (!cancellation.isCancellationRequested) { - await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString()); + if (testInParallel) { + await commands.executeCommand(COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString(), undefined, undefined, undefined, true, projects); + } else { + await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString()); + } } } } if (this.started) { this.itemsToRun.forEach(item => this.set(item, 'skipped')); + } + // TBD - message Review Comment: TBD - for the future ? ########## java/java.lsp.server/vscode/src/testAdapter.ts: ########## @@ -63,53 +87,122 @@ export class NbTestAdapter { for (let item of include) { if (item.uri) { this.set(item, 'enqueued'); + item.parent?.children.forEach(child => { + if (child.id?.includes(item.id)) { + this.set(child, 'enqueued'); + } + }) const idx = item.id.indexOf(':'); + const nestedClassIdx = item.id.indexOf('$'); + let nestedClass: string | undefined; + if (nestedClassIdx > 0) { + nestedClass = idx < 0 + ? item.id.slice(nestedClassIdx + 1) + : item.id.substring(nestedClassIdx + 1, idx); + } if (!cancellation.isCancellationRequested) { - await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1)); + await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.single' : COMMAND_PREFIX + '.run.single', item.uri.toString(), idx < 0 ? undefined : item.id.slice(idx + 1), nestedClass); } } } } else { this.testController.items.forEach(item => this.set(item, 'enqueued')); for (let workspaceFolder of workspace.workspaceFolders || []) { if (!cancellation.isCancellationRequested) { - await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString()); + if (testInParallel) { + await commands.executeCommand(COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString(), undefined, undefined, undefined, true, projects); + } else { + await commands.executeCommand(request.profile?.kind === TestRunProfileKind.Debug ? COMMAND_PREFIX + '.debug.test': COMMAND_PREFIX + '.run.test', workspaceFolder.uri.toString()); + } } } } if (this.started) { this.itemsToRun.forEach(item => this.set(item, 'skipped')); + } + // TBD - message + else { + this.itemsToRun.forEach(item => this.set(item, 'failed', new TestMessage('Build failure'), false, true)); } this.itemsToRun = undefined; this.currentRun.end(); this.currentRun = undefined; } } - set(item: TestItem, state: 'enqueued' | 'started' | 'passed' | 'failed' | 'skipped' | 'errored', message?: TestMessage | readonly TestMessage[], noPassDown? : boolean): void { + set(item: TestItem, state: SuiteState, message?: TestMessage | readonly TestMessage[], noPassDown? : boolean, dispatchBuildFailEvent?: boolean): void { if (this.currentRun) { switch (state) { case 'enqueued': + this.dispatchTestEvent(state, item); this.itemsToRun?.add(item); this.currentRun.enqueued(item); break; + case 'skipped': + this.dispatchTestEvent(state, item); case 'started': case 'passed': - case 'skipped': this.itemsToRun?.delete(item); this.currentRun[state](item); break; case 'failed': case 'errored': + if (dispatchBuildFailEvent) { + this.dispatchTestEvent(state, item); + } this.itemsToRun?.delete(item); this.currentRun[state](item, message || new TestMessage("")); break; } + this.suiteStates.set(item, state); if (!noPassDown) { - item.children.forEach(child => this.set(child, state, message, noPassDown)); + item.children.forEach(child => this.set(child, state, message, noPassDown, dispatchBuildFailEvent)); } } } + + dispatchTestEvent(state: SuiteState, testItem: TestItem): void { + if (testItem.parent && testItem.children.size > 0) { + this.dispatchEvent({ + name: testItem.id, + moduleName: testItem.parent?.id, Review Comment: nitpick: unnecessary parent?. as parent was checked to be non-falsy above. -- 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
