diff --git a/extension/src/tasks/taskUtil.ts b/extension/src/tasks/taskUtil.ts index c57647729..aa37248e3 100644 --- a/extension/src/tasks/taskUtil.ts +++ b/extension/src/tasks/taskUtil.ts @@ -246,13 +246,13 @@ function getVSCodeTasksFromGradleProject( gradleProject: GradleProject, client: GradleClient ): vscode.Task[] { - const projects: Array = [gradleProject]; - const vsCodeTasks: vscode.Task[] = []; + let projects: Array = [gradleProject]; + let vsCodeTasks: vscode.Task[] = []; while (projects.length) { const project = projects.pop(); const gradleTasks: GradleTask[] | void = project!.getTasksList(); for (const gradleTask of gradleTasks) { - vsCodeTasks.push( + vsCodeTasks = vsCodeTasks.concat( createVSCodeTaskFromGradleTask( taskTerminalsStore, gradleTask, @@ -261,9 +261,7 @@ function getVSCodeTasksFromGradleProject( ) ); } - for (const childProject of project!.getProjectsList()) { - projects.push(childProject); - } + projects = projects.concat(project!.getProjectsList()); } return vsCodeTasks; @@ -287,14 +285,13 @@ export async function loadTasksForProjectRoots( const gradleBuild = await getGradleBuild(client, rootProject); const gradleProject = gradleBuild && gradleBuild.getProject(); if (gradleProject) { - allTasks = allTasks.concat( - getVSCodeTasksFromGradleProject( - taskTerminalsStore, - rootProject, - gradleProject, - client - ) + const vsCodeTasks = getVSCodeTasksFromGradleProject( + taskTerminalsStore, + rootProject, + gradleProject, + client ); + allTasks = allTasks.concat(vsCodeTasks); } } } diff --git a/extension/src/terminal/GradleRunnerTerminal.ts b/extension/src/terminal/GradleRunnerTerminal.ts index c1b9fc353..c2a5eaff9 100644 --- a/extension/src/terminal/GradleRunnerTerminal.ts +++ b/extension/src/terminal/GradleRunnerTerminal.ts @@ -17,7 +17,7 @@ const nlRegExp = new RegExp(`${NL}([^${CR}]|$)`, 'g'); export class GradleRunnerTerminal { private readonly writeEmitter = new vscode.EventEmitter(); - private stdOutLoggerStream: LoggerStream; + private stdOutLoggerStream: LoggerStream | undefined; private readonly closeEmitter = new vscode.EventEmitter(); private task?: vscode.Task; public readonly onDidWrite: vscode.Event = this.writeEmitter.event; @@ -29,8 +29,10 @@ export class GradleRunnerTerminal { private readonly cancellationKey: string, private readonly client: GradleClient ) { - // TODO: this is only needed for the tests. Find a better way to test task output in the tests. - this.stdOutLoggerStream = new LoggerStream(logger, LogVerbosity.INFO); + if (isTest()) { + // TODO: this is only needed for the tests. Find a better way to test task output in the tests. + this.stdOutLoggerStream = new LoggerStream(logger, LogVerbosity.INFO); + } } public async open(): Promise { @@ -121,7 +123,7 @@ export class GradleRunnerTerminal { private handleOutput = (output: Output): void => { const messageBytes = output.getOutputBytes_asU8(); if (messageBytes.length) { - if (isTest()) { + if (isTest() && this.stdOutLoggerStream) { this.stdOutLoggerStream.write(messageBytes); } this.write(new util.TextDecoder('utf-8').decode(messageBytes)); diff --git a/extension/src/test/unit/taskUtil.test.ts b/extension/src/test/unit/taskUtil.test.ts index cde4538f6..3b7cd034a 100644 --- a/extension/src/test/unit/taskUtil.test.ts +++ b/extension/src/test/unit/taskUtil.test.ts @@ -10,6 +10,23 @@ import { TaskTerminalsStore } from '../../stores'; import { loadTasksForProjectRoots } from '../../tasks/taskUtil'; import { buildMockClient, getSuiteName } from '../testUtil'; +const mockWorkspaceFolder: vscode.WorkspaceFolder = { + index: 0, + uri: vscode.Uri.file('folder1'), + name: 'folder1', +}; + +const mockRootProject = new RootProject( + mockWorkspaceFolder, + vscode.Uri.file('folder1'), + { + tasks: [], + clean: false, + } +); +const mockClient = buildMockClient(); +const mockTaskTerminalsStore = new TaskTerminalsStore(); + function buildProject( project: string, rootProject: string, @@ -61,23 +78,6 @@ function getDeeplyNestedProjectTree( return projects; } -const workspaceFolder: vscode.WorkspaceFolder = { - index: 0, - uri: vscode.Uri.file('folder1'), - name: 'folder1', -}; - -const rootProject = new RootProject( - workspaceFolder, - vscode.Uri.file('folder1'), - { - tasks: [], - clean: false, - } -); -const client = buildMockClient(); -const taskTerminalsStore = new TaskTerminalsStore(); - describe(getSuiteName('taskUtil'), () => { afterEach(() => { sinon.restore(); @@ -99,11 +99,13 @@ describe(getSuiteName('taskUtil'), () => { ); rootGradleProject.setProjectsList([childGradleProject]); gradleBuild.setProject(rootGradleProject); - client.getBuild.resolves(Promise.resolve(gradleBuild)); + mockClient.getBuild.resolves(Promise.resolve(gradleBuild)); - const tasks = await loadTasksForProjectRoots(taskTerminalsStore, client, [ - rootProject, - ]); + const tasks = await loadTasksForProjectRoots( + mockTaskTerminalsStore, + mockClient, + [mockRootProject] + ); assert.strictEqual(tasks.length, 2); }); @@ -128,11 +130,13 @@ describe(getSuiteName('taskUtil'), () => { rootGradleProject.setProjectsList(projectsList); gradleBuild.setProject(rootGradleProject); - client.getBuild.resolves(Promise.resolve(gradleBuild)); + mockClient.getBuild.resolves(Promise.resolve(gradleBuild)); - const tasks = await loadTasksForProjectRoots(taskTerminalsStore, client, [ - rootProject, - ]); + const tasks = await loadTasksForProjectRoots( + mockTaskTerminalsStore, + mockClient, + [mockRootProject] + ); assert.strictEqual(tasks.length, 382651); }); });