@@ -8,6 +8,7 @@ import CxResult from "../results/CxResult";
88import CxProject from "../project/CxProject" ;
99import CxCodeBashing from "../codebashing/CxCodeBashing" ;
1010import CxBFL from "../bfl/CxBFL" ;
11+ import CxKicsRealTime from "../kicsRealtime/CxKicsRealTime" ;
1112
1213const spawn = require ( 'child_process' ) . spawn ;
1314
@@ -33,33 +34,79 @@ function transform(n:string) {
3334}
3435
3536export class ExecutionService {
37+ private fsObject : any = undefined
38+
3639 executeCommands ( pathToExecutable : string , commands : string [ ] , output ? : string ) : Promise < CxCommandOutput > {
37- return new Promise ( function ( resolve , reject ) {
40+ return ( new Promise ( ( resolve , reject ) => {
3841 let stderr = "" ;
3942 let stdout = "" ;
4043
41- let cp = spawn ( pathToExecutable , transformation ( commands ) ) ;
42- cp . on ( 'error' , reject ) ;
43- cp . on ( 'exit' , ( code : number , signal : any ) => {
44+ this . fsObject = spawn ( pathToExecutable , transformation ( commands ) ) ;
45+ this . fsObject . on ( 'error' , ( data : { toString : ( ) => string ; } ) => {
46+ if ( data ) {
47+ logger . error ( data . toString ( ) . replace ( '\n' , '' ) ) ;
48+ stderr += data . toString ( ) ;
49+ }
50+ reject ( )
51+ } ) ;
52+ this . fsObject . on ( 'exit' , ( code : number , signal : any ) => {
4453 logger . info ( "Exit code received from AST-CLI: " + code ) ;
45- resolve ( ExecutionService . onCloseCommand ( code , stderr , stdout , output ) ) ;
54+ if ( code == 1 ) {
55+ stderr = stdout
56+ }
57+ resolve ( ExecutionService . onCloseCommand ( code , stderr , stdout , output , this . fsObject ) ) ;
4658 } ) ;
47- cp . stdout . on ( 'data' , ( data : { toString : ( ) => string ; } ) => {
59+ this . fsObject . stdout . on ( 'data' , ( data : { toString : ( ) => string ; } ) => {
4860 if ( data ) {
4961 logger . info ( data . toString ( ) . replace ( '\n' , '' ) ) ;
5062 stdout += data . toString ( ) ;
5163 }
5264 } ) ;
53- cp . stderr . on ( 'data' , ( data : { toString : ( ) => string ; } ) => {
65+ this . fsObject . stderr . on ( 'data' , ( data : { toString : ( ) => string ; } ) => {
5466 if ( data ) {
5567 logger . error ( data . toString ( ) . replace ( '\n' , '' ) ) ;
5668 stderr += data . toString ( ) ;
5769 }
5870 } ) ;
59- } ) ;
71+ } ) ) ;
72+ }
73+
74+ executeKicsCommands ( pathToExecutable : string , commands : string [ ] , output ? : string ) : [ Promise < CxCommandOutput > , any ] {
75+ return [ new Promise ( ( resolve , reject ) => {
76+ let stderr = "" ;
77+ let stdout = "" ;
78+
79+ this . fsObject = spawn ( pathToExecutable , transformation ( commands ) ) ;
80+ this . fsObject . on ( 'error' , ( data : { toString : ( ) => string ; } ) => {
81+ if ( data ) {
82+ logger . error ( data . toString ( ) . replace ( '\n' , '' ) ) ;
83+ stderr += data . toString ( ) ;
84+ }
85+ reject ( )
86+ } ) ;
87+ this . fsObject . on ( 'exit' , ( code : number , signal : any ) => {
88+ logger . info ( "Exit code received from AST-CLI: " + code ) ;
89+ if ( code == 1 ) {
90+ stderr = stdout
91+ }
92+ resolve ( ExecutionService . onCloseCommand ( code , stderr , stdout , output , this . fsObject ) ) ;
93+ } ) ;
94+ this . fsObject . stdout . on ( 'data' , ( data : { toString : ( ) => string ; } ) => {
95+ if ( data ) {
96+ logger . info ( data . toString ( ) . replace ( '\n' , '' ) ) ;
97+ stdout += data . toString ( ) ;
98+ }
99+ } ) ;
100+ this . fsObject . stderr . on ( 'data' , ( data : { toString : ( ) => string ; } ) => {
101+ if ( data ) {
102+ logger . error ( data . toString ( ) . replace ( '\n' , '' ) ) ;
103+ stderr += data . toString ( ) ;
104+ }
105+ } ) ;
106+ } ) , this . fsObject ] ;
60107 }
61108
62- private static onCloseCommand ( code : number , stderr : string , stdout : string , output : string ) : CxCommandOutput {
109+ private static onCloseCommand ( code : number , stderr : string , stdout : string , output : string , fsObject : any ) : CxCommandOutput {
63110 const cxCommandOutput = new CxCommandOutput ( ) ;
64111 cxCommandOutput . exitCode = code ;
65112 if ( stderr ) {
@@ -68,7 +115,6 @@ export class ExecutionService {
68115 if ( stdout ) {
69116 const stdoutSplit = stdout . split ( '\n' ) ;
70117 const data = stdoutSplit . find ( isJsonString ) ;
71-
72118 if ( data ) {
73119 let resultObject = JSON . parse ( data ) ;
74120 switch ( output ) {
@@ -88,6 +134,10 @@ export class ExecutionService {
88134 let bflNode = CxBFL . parseBFLResponse ( resultObject ) ;
89135 cxCommandOutput . payload = bflNode ;
90136 break ;
137+ case "CxKicsRealTime" :
138+ let kicsResults = CxKicsRealTime . parseKicsRealTimeResponse ( resultObject ) ;
139+ cxCommandOutput . payload = [ kicsResults ] ;
140+ break ;
91141 default :
92142 cxCommandOutput . payload = resultObject ;
93143 }
0 commit comments