Skip to content

Commit ca75d11

Browse files
authored
fix: "Cancel" of generating jar takes no effect (#497)
1 parent c2a1a74 commit ca75d11

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public static ExportResult exportJar(List<Object> arguments, IProgressMonitor mo
155155
if (arguments.size() < 3) {
156156
return new ExportResult(false, "Invalid export Arguments");
157157
}
158+
if (monitor.isCanceled()) {
159+
return new ExportResult(false, "User cancelled");
160+
}
158161
String mainClass = gson.fromJson(gson.toJson(arguments.get(0)), String.class);
159162
Classpath[] classpaths = gson.fromJson(gson.toJson(arguments.get(1)), Classpath[].class);
160163
String destination = gson.fromJson(gson.toJson(arguments.get(2)), String.class);
@@ -166,6 +169,9 @@ public static ExportResult exportJar(List<Object> arguments, IProgressMonitor mo
166169
try (JarOutputStream target = new JarOutputStream(new FileOutputStream(destination), manifest)) {
167170
Set<String> directories = new HashSet<>();
168171
for (Classpath classpath : classpaths) {
172+
if (monitor.isCanceled()) {
173+
return new ExportResult(false, "User cancelled");
174+
}
169175
if (classpath.isArtifact) {
170176
writeArchive(new ZipFile(classpath.source), /* areDirectoryEntriesIncluded = */true,
171177
/* isCompressed = */true, target, directories, monitor);

src/exportJarSteps/GenerateJarExecutor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class GenerateJarExecutor implements IExportJarStepExecutor {
8282
if (_.isEmpty(classpaths)) {
8383
return reject(new Error(ExportJarMessages.CLASSPATHS_EMPTY));
8484
}
85-
const exportResult: IExportResult | undefined = await Jdtls.exportJar(basename(mainClass), classpaths, destPath);
85+
const exportResult: IExportResult | undefined = await Jdtls.exportJar(basename(mainClass), classpaths, destPath, token);
8686
if (exportResult?.result === true) {
8787
stepMetadata.outputPath = destPath;
8888
return resolve(true);

src/java/jdtls.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { commands } from "vscode";
4+
import { CancellationToken, commands } from "vscode";
55
import { Commands, executeJavaLanguageServerCommand } from "../commands";
66
import { IExportResult } from "../exportJarSteps/GenerateJarExecutor";
77
import { IClasspath } from "../exportJarSteps/IStepMetadata";
@@ -29,9 +29,10 @@ export namespace Jdtls {
2929
return await commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_GETMAINCLASSES, params) || [];
3030
}
3131

32-
export async function exportJar(mainClass: string, classpaths: IClasspath[], destination: string): Promise<IExportResult | undefined> {
32+
export async function exportJar(mainClass: string, classpaths: IClasspath[],
33+
destination: string, token: CancellationToken): Promise<IExportResult | undefined> {
3334
return commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.JAVA_PROJECT_GENERATEJAR,
34-
mainClass, classpaths, destination);
35+
mainClass, classpaths, destination, token);
3536
}
3637

3738
export enum CompileWorkspaceStatus {

0 commit comments

Comments
 (0)