package Ġio . sn yk . plugin . cli Ċ Ċ import Ġcom . intellij . execution . ExecutionException Ċ import Ġcom . intellij . execution . configurations . General CommandLine Ċ import Ġcom . intellij . execution . process . OS Process Handler Ċ import Ġcom . intellij . execution . process . Process Adapter Ċ import Ġcom . intellij . execution . process . Process Event Ċ import Ġcom . intellij . execution . process . Script Runner Util Ċ import Ġcom . intellij . ide . plugins . PluginManager Core Ċ import Ġcom . intellij . openapi . application . Application Info Ċ import Ġcom . intellij . openapi . progress . Progress Manager Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . util . Key Ċ import Ġio . sn yk . plugin . S ny k Post Startup Activity Ċ import Ġio . sn yk . plugin . ui . S ny k Bal loon Notifications Ċ import Ġio . sn yk . plugin . control External Process With Progress Indicator Ċ import Ġorg . apache . log 4 j . Logger Ċ import Ġjava . nio . charset . Charset Ċ Ċ open Ġclass ĠConsole Command Runner Ġ{ ĊĠĠĠ Ġprivate Ġval Ġlogger : ĠLogger Ġ= ĠLogger . getLogger ( Console Command Runner :: class . java ) ĊĊĠĠĠ Ġprivate Ġval Ġs ny k Plugin Version : ĠString Ġby Ġlazy Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfeature Trainer Plugin Id Ġ= ĠPlugin Manager Core . get Plugin By ClassName ( S ny k Post Startup Activity :: class . java . name ) ĊĠĠĠĠĠĠĠ ĠPlugin Manager Core . get Plugin ( feature Trainer Plugin Id )?. version Ġ?: Ġ" UNKNOWN " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġopen Ġfun Ġexecute ( ĊĠĠĠĠĠĠĠ Ġcommands : ĠList < String >, ĊĠĠĠĠĠĠĠ Ġwork Directory : ĠString Ġ= Ġ"/", ĊĠĠĠĠĠĠĠ Ġapi Token : ĠString Ġ= Ġ"", ĊĠĠĠĠĠĠĠ Ġproject : ĠProject , ĊĠĠĠĠĠĠĠ Ġoutput Consumer : Ġ( line : ĠString ) Ġ-> ĠUnit Ġ= Ġ{} ĊĠĠĠ Ġ): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . info (" Enter ĠConsole Command Runner . execute () ") ĊĠĠĠĠĠĠĠ Ġlogger . info (" Commands : Ġ$ commands ") ĊĊĠĠĠĠĠĠĠ Ġval Ġgeneral CommandLine Ġ= ĠGeneral CommandLine ( commands ) ĊĊĠĠĠĠĠĠĠ Ġgeneral CommandLine . charset Ġ= ĠCharset . forName (" UTF - 8 ") ĊĠĠĠĠĠĠĠ Ġgeneral CommandLine . set Work Directory ( work Directory ) ĊĊĠĠĠĠĠĠĠ Ġsetup Cli Environment Variables ( general CommandLine , Ġapi Token ) ĊĊĠĠĠĠĠĠĠ Ġlogger . info (" General CommandLine Ġinstance Ġcreated .") ĊĊĠĠĠĠĠĠĠ Ġval Ġprocess Handler Ġ= Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠOS Process Handler ( general CommandLine ) ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( e : ĠExecution Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// Ġ Ġif ĠCLI Ġis Ġstill Ġdownloading Ġ( or Ġtemporarily Ġblocked Ġby ĠAnt ivirus ) Ġwe 'll Ġget ĠProcess Not Created Exception ĊĠĠĠĠĠĠĠĠĠĠĠ ĠS ny k Bal loon Notifications . show Warn (" Not Ġable Ġto Ġrun ĠCLI , Ġtry Ġagain Ġlater .", Ġproject ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn Ġ"" ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġparent Indicator Ġ= ĠProgress Manager . getInstance (). progress Indicator ĊĊĠĠĠĠĠĠĠ Ġprocess Handler . add Process Listener ( object Ġ: ĠProcess Adapter () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon Text Available ( event : ĠProcess Event , Ġoutput Type : ĠKey <* >) Ġ= Ġoutput Consumer ( event . text ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĊĠĠĠĠĠĠĠ Ġvar Ġwas Process Terminated Ġ= Ġfalse ĊĠĠĠĠĠĠĠ Ġcontrol External Process With Progress Indicator ( parent Indicator ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ(! process Handler . is Process Terminated ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠScript Runner Util . terminate Process Handler ( process Handler , Ġ 5 0 , Ġnull ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwas Process Terminated Ġ= Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġlogger . info (" Execute ĠScript Runner Util . get Process Output (...) ") ĊĠĠĠĠĠĠĠ Ġval Ġprocess Output Ġ= ĠScript Runner Util . get Process Output ( process Handler , ĠScript Runner Util . STDOUT _ OUTPUT _ KEY _ FILTER , Ġ 7 2 0 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġreturn Ġif Ġ( was Process Terminated ) ĠPROCESS _ CANCEL LED _ BY _ USER Ġelse Ġprocess Output ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠSetup Ġenvironment Ġvariables Ġfor ĠCLI . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġfun Ġsetup Cli Environment Variables ( general CommandLine : ĠGeneral CommandLine , Ġapi Token : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( api Token . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgeneral CommandLine . environment [" SN YK _ TOKEN "] Ġ= Ġapi Token ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġgeneral CommandLine . environment [" SN YK _ INTEGR ATION _ NAME "] Ġ= Ġ" J ET BR AIN S _ IDE " ĊĠĠĠĠĠĠĠ Ġgeneral CommandLine . environment [" SN YK _ INTEGR ATION _ VERSION "] Ġ= Ġs ny k Plugin Version ĊĊĠĠĠĠĠĠĠ Ġval Ġapplication Info Ġ= ĠApplication Info . getInstance () ĊĊĠĠĠĠĠĠĠ Ġval Ġversion Name Ġ= Ġwhen Ġ( val Ġname Ġ= Ġapplication Info . version Name ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Int elli J ĠIDEA ", Ġ" Py Char m " Ġ-> Ġ"$ name Ġ${ application Info . apiVersion . substring ( 0 , Ġ 2 )}" ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġname ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġgeneral CommandLine . environment [" SN YK _ INTEGR ATION _ ENVIRONMENT "] Ġ= Ġversion Name . toUpperCase () ĊĠĠĠĠĠĠĠ Ġgeneral CommandLine . environment [" SN YK _ INTEGR ATION _ ENVIRONMENT _ VERSION "] Ġ= Ġapplication Info . full Version ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġconst Ġval ĠPROCESS _ CANCEL LED _ BY _ USER Ġ= Ġ" PROCESS _ CANCEL LED _ BY _ USER " ĊĠĠĠ Ġ} Ċ } Ċ