@@ -22,7 +22,7 @@ import { IClasspath, IStepMetadata } from "./IStepMetadata";
2222import { IMainClassInfo } from "./ResolveMainClassExecutor" ;
2323import {
2424 ExportJarConstants , ExportJarMessages , ExportJarStep , failMessage , getExtensionApi ,
25- resetStepMetadata , stepMap , successMessage , toPosixPath , toWinPath ,
25+ resetStepMetadata , revealTerminal , stepMap , successMessage , toPosixPath , toWinPath ,
2626} from "./utility" ;
2727
2828interface IExportJarTaskDefinition extends TaskDefinition {
@@ -33,6 +33,8 @@ interface IExportJarTaskDefinition extends TaskDefinition {
3333}
3434
3535let isExportingJar : boolean = false ;
36+ // key: terminalId, value: ExportJarTaskTerminal
37+ const activeTerminalMap : Map < string , ExportJarTaskTerminal > = new Map < string , ExportJarTaskTerminal > ( ) ;
3638
3739export async function executeExportJarTask ( node ?: INodeData ) : Promise < void > {
3840 // save the workspace first
@@ -168,21 +170,32 @@ class ExportJarTaskTerminal implements Pseudoterminal {
168170 public onDidWrite : Event < string > = this . writeEmitter . event ;
169171 public onDidClose ?: Event < void > = this . closeEmitter . event ;
170172
173+ public terminalId : string ;
171174 private stepMetadata : IStepMetadata ;
172175
173176 constructor ( exportJarTaskDefinition : IExportJarTaskDefinition , stepMetadata : IStepMetadata ) {
174177 this . stepMetadata = stepMetadata ;
175178 this . stepMetadata . taskLabel = exportJarTaskDefinition . label || "" ;
179+ this . stepMetadata . terminalId = Math . floor ( Math . random ( ) * Number . MAX_SAFE_INTEGER ) . toString ( ) ;
176180 this . stepMetadata . mainClass = exportJarTaskDefinition . mainClass ;
177181 this . stepMetadata . outputPath = exportJarTaskDefinition . targetPath ;
178182 this . stepMetadata . elements = exportJarTaskDefinition . elements || [ ] ;
183+ this . terminalId = this . stepMetadata . terminalId ;
179184 }
180185
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+ }
183194 }
184195
185196 public async open ( _initialDimensions : TerminalDimensions | undefined ) : Promise < void > {
197+ activeTerminalMap . set ( this . terminalId , this ) ;
198+ revealTerminal ( this . stepMetadata . taskLabel ) ;
186199 let exportResult : boolean | undefined ;
187200 try {
188201 if ( ! this . stepMetadata . workspaceFolder ) {
@@ -210,17 +223,21 @@ class ExportJarTaskTerminal implements Pseudoterminal {
210223 } catch ( err ) {
211224 if ( err ) {
212225 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" ) ;
213229 }
214230 } finally {
215231 isExportingJar = false ;
216232 if ( exportResult === true ) {
217233 successMessage ( this . stepMetadata . outputPath ) ;
234+ this . exit ( "[SUCCESS] Export Jar process is finished successfully" ) ;
218235 } else if ( exportResult === false ) {
219236 // We call `executeExportJarTask()` with the same entry here
220237 // to help the user reselect the Java project.
221238 executeExportJarTask ( this . stepMetadata . entry ) ;
222239 }
223- this . closeEmitter . fire ( ) ;
240+ this . exit ( ) ;
224241 }
225242 }
226243
@@ -406,3 +423,11 @@ class ExportJarTaskTerminal implements Pseudoterminal {
406423 return negative ? "!" + positivePath : positivePath ;
407424 }
408425}
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