@@ -22,7 +22,7 @@ import { IClasspath, IStepMetadata } from "./IStepMetadata";
22
22
import { IMainClassInfo } from "./ResolveMainClassExecutor" ;
23
23
import {
24
24
ExportJarConstants , ExportJarMessages , ExportJarStep , failMessage , getExtensionApi ,
25
- resetStepMetadata , stepMap , successMessage , toPosixPath , toWinPath ,
25
+ resetStepMetadata , revealTerminal , stepMap , successMessage , toPosixPath , toWinPath ,
26
26
} from "./utility" ;
27
27
28
28
interface IExportJarTaskDefinition extends TaskDefinition {
@@ -33,6 +33,8 @@ interface IExportJarTaskDefinition extends TaskDefinition {
33
33
}
34
34
35
35
let isExportingJar : boolean = false ;
36
+ // key: terminalId, value: ExportJarTaskTerminal
37
+ const activeTerminalMap : Map < string , ExportJarTaskTerminal > = new Map < string , ExportJarTaskTerminal > ( ) ;
36
38
37
39
export async function executeExportJarTask ( node ?: INodeData ) : Promise < void > {
38
40
// save the workspace first
@@ -168,21 +170,32 @@ class ExportJarTaskTerminal implements Pseudoterminal {
168
170
public onDidWrite : Event < string > = this . writeEmitter . event ;
169
171
public onDidClose ?: Event < void > = this . closeEmitter . event ;
170
172
173
+ public terminalId : string ;
171
174
private stepMetadata : IStepMetadata ;
172
175
173
176
constructor ( exportJarTaskDefinition : IExportJarTaskDefinition , stepMetadata : IStepMetadata ) {
174
177
this . stepMetadata = stepMetadata ;
175
178
this . stepMetadata . taskLabel = exportJarTaskDefinition . label || "" ;
179
+ this . stepMetadata . terminalId = Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER ) . toString ( ) ;
176
180
this . stepMetadata . mainClass = exportJarTaskDefinition . mainClass ;
177
181
this . stepMetadata . outputPath = exportJarTaskDefinition . targetPath ;
178
182
this . stepMetadata . elements = exportJarTaskDefinition . elements || [ ] ;
183
+ this . terminalId = this . stepMetadata . terminalId ;
179
184
}
180
185
181
- public handleInput ( data : string ) : void {
182
- this . writeEmitter . fire ( data + EOL ) ;
186
+ public exit ( message ?: string ) {
187
+ if ( message ) {
188
+ this . writeEmitter . fire ( message ) ;
189
+ }
190
+ if ( activeTerminalMap . has ( this . terminalId ) ) {
191
+ activeTerminalMap . delete ( this . terminalId ) ;
192
+ this . closeEmitter . fire ( ) ;
193
+ }
183
194
}
184
195
185
196
public async open ( _initialDimensions : TerminalDimensions | undefined ) : Promise < void > {
197
+ activeTerminalMap . set ( this . terminalId , this ) ;
198
+ revealTerminal ( this . stepMetadata . taskLabel ) ;
186
199
let exportResult : boolean | undefined ;
187
200
try {
188
201
if ( ! this . stepMetadata . workspaceFolder ) {
@@ -210,17 +223,21 @@ class ExportJarTaskTerminal implements Pseudoterminal {
210
223
} catch ( err ) {
211
224
if ( err ) {
212
225
failMessage ( `${ err } ` ) ;
226
+ this . exit ( "[ERROR] An error occurs during export Jar process" ) ;
227
+ } else {
228
+ this . exit ( "[CANCEL] Export Jar process is cancelled by user" ) ;
213
229
}
214
230
} finally {
215
231
isExportingJar = false ;
216
232
if ( exportResult === true ) {
217
233
successMessage ( this . stepMetadata . outputPath ) ;
234
+ this . exit ( "[SUCCESS] Export Jar process is finished successfully" ) ;
218
235
} else if ( exportResult === false ) {
219
236
// We call `executeExportJarTask()` with the same entry here
220
237
// to help the user reselect the Java project.
221
238
executeExportJarTask ( this . stepMetadata . entry ) ;
222
239
}
223
- this . closeEmitter . fire ( ) ;
240
+ this . exit ( ) ;
224
241
}
225
242
}
226
243
@@ -406,3 +423,11 @@ class ExportJarTaskTerminal implements Pseudoterminal {
406
423
return negative ? "!" + positivePath : positivePath ;
407
424
}
408
425
}
426
+
427
+ export function appendOutput ( terminalId : string , message : string ) : void {
428
+ const terminal = activeTerminalMap . get ( terminalId ) ;
429
+ if ( ! terminal ) {
430
+ return ;
431
+ }
432
+ terminal . writeEmitter . fire ( message + EOL ) ;
433
+ }
0 commit comments