// ĠCopyright Ġ 2 0 0 0 - 2 0 1 9 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġcom . intellij . internal . statistic . actions Ċ Ċ import Ġcom . intellij . diagnostic . logging . Log Console Base Ċ import Ġcom . intellij . diagnostic . logging . Log Filter Ċ import Ġcom . intellij . diagnostic . logging . Log Filter Listener Ċ import Ġcom . intellij . diagnostic . logging . Log Filter Model Ċ import Ġcom . intellij . execution . process . Process OutputType Ċ import Ġcom . intellij . internal . statistic . Statistics Bundle Ċ import Ġcom . intellij . internal . statistic . actions . Statistics Event Log Tool Window . Companion . rejected Validation Types Ċ import Ġcom . intellij . internal . statistic . event Log . Event Log Notification Service Ċ import Ġcom . intellij . internal . statistic . event Log . Log Event Ċ import Ġcom . intellij . internal . statistic . event Log . validator . Validation Result Type .* Ċ import Ġcom . intellij . openapi . Disposable Ċ import Ġcom . intellij . openapi . action System . Action Manager Ċ import Ġcom . intellij . openapi . action System . Default Action Group Ċ import Ġcom . intellij . openapi . progress . Progress Indicator Ċ import Ġcom . intellij . openapi . progress . Progress Manager Ċ import Ġcom . intellij . openapi . progress . Task Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . ui . Simple Tool Window Panel Ċ import Ġcom . intellij . openapi . util . Dis poser Ċ import Ġcom . intellij . openapi . wm . Tool WindowManager Ċ import Ġcom . intellij . ui . Filter Component Ċ import Ġcom . intellij . ui . JB Color Ċ import Ġcom . intellij . util . containers . Container Util Ċ import Ġcom . intellij . util . text . DateFormat Util Ċ import Ġjava . awt . Border Layout Ċ import Ġjava . awt . Flow Layout Ċ import Ġjavax . swing . Border Factory Ċ import Ġjavax . swing . J Component Ċ import Ġjavax . swing . JPanel Ċ Ċ const Ġval Ġevent Log Tool Windows Id Ġ= Ġ" Statistics ĠEvent ĠLog " Ċ Ċ class ĠStatistics Event Log Tool Window ( project : ĠProject , Ġprivate Ġval Ġrec orderId : ĠString ) Ġ: ĠSimple Tool Window Panel ( false , Ġtrue ), ĠDis posable Ġ{ ĊĠ Ġprivate Ġval Ġconsole Log Ġ= ĠStatistics Event Log Console ( project , ĠStatistics Log Filter Model ()) ĊĠ Ġprivate Ġval Ġevent Log Listener : Ġ( Log Event ) Ġ-> ĠUnit Ġ= Ġ{ Ġlog Event Ġ-> Ġconsole Log . add Log Line ( build Log Message ( log Event )) Ġ} ĊĊĠ Ġinit Ġ{ ĊĠĠĠ Ġval Ġtop Panel Ġ= ĠJPanel ( Flow Layout ( Flow Layout . LEFT )) ĊĠĠĠ Ġtop Panel . add ( console Log . filter ) ĊĠĠĠ Ġtop Panel . add ( create Action Toolbar ()) ĊĠĠĠ Ġtop Panel . border Ġ= ĠBorder Factory . create Mat te Border ( 0 , Ġ 0 , Ġ 1 , Ġ 0 , ĠJ B Color . border ()) ĊĠĠĠ Ġadd ( top Panel , ĠBorderLayout . NORTH ) ĊĊĠĠĠ Ġset Content ( console Log . component ) ĊĊĠĠĠ Ġtoolbar Ġ= ĠAction Manager . getInstance (). create Action Toolbar (" F us Event Log Tool Window ", Ġconsole Log . or Create Actions , Ġfalse ). component ĊĊĠĠĠ ĠDis poser . register ( this , Ġconsole Log ) ĊĠĠĠ ĠEvent Log Notification Service . subscribe ( event Log Listener , Ġrec orderId ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate Action Toolbar (): ĠJ Component Ġ{ ĊĠĠĠ Ġval Ġtop Toolbar Actions Ġ= ĠDefault Action Group () ĊĠĠĠ Ġtop Toolbar Actions . add ( Record State Statistics Event Log Action ( false )) ĊĠĠĠ Ġtop Toolbar Actions . add ( Open Event LogFile Action ( recorder Id )) ĊĠĠĠ Ġtop Toolbar Actions . add Separator ( Statistics Bundle . message (" stats . whitelist ")) ĊĠĠĠ Ġtop Toolbar Actions . add ( Configure Whitelist Action ( recorder Id )) ĊĠĠĠ Ġtop Toolbar Actions . add ( Update Whitelist Action ( recorder Id )) ĊĠĠĠ Ġtop Toolbar Actions . add ( Open Whitelist File Action ( recorder Id )) ĊĠĠĠ Ġtop Toolbar Actions . add Separator ( Statistics Bundle . message (" stats . local . whitelist ")) ĊĠĠĠ Ġtop Toolbar Actions . add ( Add Test Group ToLocal Whitelist Action ()) ĊĠĠĠ Ġtop Toolbar Actions . add ( Cleanup Local Whitelist Action ()) ĊĠĠĠ Ġtop Toolbar Actions . add ( Open Local Whitelist File Action ( recorder Id )) ĊĠĠĠ Ġval Ġtoolbar Ġ= ĠAction Manager . getInstance (). create Action Toolbar (" F us Event Log Tool Window ", Ġtop Toolbar Actions , Ġtrue ) ĊĠĠĠ Ġtoolbar . set Show Separator Titles ( true ) ĊĠĠĠ Ġreturn Ġtoolbar . component ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġdispose () Ġ{ ĊĠĠĠ ĠEvent Log Notification Service . unsubscribe ( event Log Listener , Ġrec orderId ) ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġprivate Ġval Ġsystem Fields Ġ= Ġset Of (" last ", Ġ" created ") ĊĠĠĠ Ġprivate Ġconst Ġval ĠprojectId Prefix Size Ġ= Ġ 8 ĊĠĠĠ Ġprivate Ġconst Ġval ĠprojectId Suffix Size Ġ= Ġ 2 ĊĠĠĠ Ġprivate Ġconst Ġval Ġmax ProjectId Size Ġ= ĠprojectId Prefix Size Ġ+ ĠprojectId Suffix Size ĊĠĠĠ Ġval Ġrejected Validation Types Ġ= Ġset Of ( RE JECT ED , ĠIN CORRECT _ RULE , ĠUN DEFINED _ RULE , ĠUN RE ACH ABLE _ WHITE LIST , ĠPER FORMANCE _ ISSUE ) ĊĊĠĠĠ Ġfun Ġbuild Log Message ( log Event : ĠLog Event ): ĠString Ġ{ ĊĠĠĠĠĠ Ġreturn Ġbuild String Ġ{ ĊĠĠĠĠĠĠĠ Ġappend ( DateFormat Util . format Time With Seconds ( log Event . time )) ĊĠĠĠĠĠĠĠ Ġappend (" Ġ- Ġ[' ${ log Event . group . id }', Ġv ${ log Event . group . version } ]: Ġ'${ log Event . event . id }' Ġ") ĊĠĠĠĠĠĠĠ Ġappend ("{ ") ĊĠĠĠĠĠĠĠ Ġappend ( build EventData Messages ( log Event )) ĊĠĠĠĠĠĠĠ Ġappend (" }") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġbuild EventData Messages ( log Event : ĠLog Event ): ĠString Ġ{ ĊĠĠĠĠĠ Ġreturn Ġlog Event . event . data ĊĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġ( key , Ġ_) Ġ-> Ġ! system Fields . contains ( key ) Ġ} ĊĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġ( key , Ġvalue ) Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġvar Ġvalue AsString Ġ= Ġvalue . toString () ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( key Ġ== Ġ" project ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġvalue AsString Ġ= Ġshort en ProjectId ( value AsString ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ"\" $ key \":\" $ value AsString \"" ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ. join ToString (", Ġ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshort en ProjectId ( projectId : ĠString ): ĠString Ġ{ ĊĠĠĠĠĠ Ġval Ġlength Ġ= ĠprojectId . length ĊĠĠĠĠĠ Ġval Ġis Rejected Ġ= Ġrejected Validation Types . any Ġ{ Ġit . description Ġ== ĠprojectId Ġ} ĊĠĠĠĠĠ Ġif Ġ(! is Rejected Ġ&& ĠprojectId . isNotBlank () Ġ&& Ġlength Ġ> Ġmax ProjectId Size ) Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġ"${ projectId . substring ( 0 , ĠprojectId Prefix Size )} ... ${ projectId . substring ( length Ġ- ĠprojectId Suffix Size , Ġlength )}" ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠprojectId ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠ Ġ} Ċ } Ċ Ċ private Ġclass ĠStatistics Event Log Console ( val Ġproject : ĠProject , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġmodel : ĠLog Filter Model ) Ġ: ĠLog Console Base ( project , Ġnull , Ġevent Log Tool Windows Id , Ġfalse , Ġmodel ) Ġ{ ĊĠ Ġval Ġfilter Ġ= Ġobject Ġ: ĠFilter Component (" STAT ISTICS _ EVENT _ LOG _ FILTER _ HISTORY ", Ġ 5 ) Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġfilter () Ġ{ ĊĠĠĠĠĠ Ġval Ġtask Ġ= Ġobject Ġ: ĠTask . Background able ( project , ĠAP PLY ING _ FILTER _ TITLE ) Ġ{ ĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġrun ( indicator : ĠProgress Indicator ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġmodel . update Custom Filter ( filter ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠProgress Manager . getInstance (). run ( task ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠisActive (): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn ĠTool WindowManager . getInstance ( project ). get Tool Window ( event Log Tool Windows Id )?. isVisible Ġ?: Ġfalse ĊĠ Ġ} ĊĊĠ Ġfun Ġadd Log Line ( line : ĠString ) Ġ{ ĊĠĠĠ Ġsuper . addMessage ( line ) ĊĠ Ġ} Ċ } Ċ Ċ class ĠStatistics Log Filter Model Ġ: ĠLog Filter Model () Ġ{ ĊĠ Ġprivate Ġval Ġlisteners Ġ= ĠContainer Util . create Lock Free Copy On Write List < Log Filter Listener >() ĊĠ Ġprivate Ġvar Ġcustom Filter : ĠString ? Ġ= Ġnull ĊĊĊĠ Ġoverride Ġfun Ġget Custom Filter (): ĠString ? Ġ= Ġcustom Filter ĊĊĠ Ġoverride Ġfun Ġadd Filter Listener ( listener : ĠLog Filter Listener ?) Ġ{ ĊĠĠĠ Ġlisteners . add ( listener ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġremove Filter Listener ( listener : ĠLog Filter Listener ?) Ġ{ ĊĠĠĠ Ġlisteners . remove ( listener ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġget Log Filters (): ĠList < Log Filter > Ġ= Ġempty List () ĊĊĠ Ġoverride Ġfun Ġis Filter Selected ( filter : ĠLog Filter ?): ĠBoolean Ġ= Ġfalse ĊĊĠ Ġoverride Ġfun Ġselect Filter ( filter : ĠLog Filter ?) Ġ{} ĊĊĠ Ġoverride Ġfun Ġupdate Custom Filter ( filter : ĠString ) Ġ{ ĊĠĠĠ Ġsuper . update Custom Filter ( filter ) ĊĠĠĠ Ġcustom Filter Ġ= Ġfilter ĊĠĠĠ Ġfor Ġ( listener Ġin Ġlisteners ) Ġ{ ĊĠĠĠĠĠ Ġlistener . on Text Filter Change () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġprocess Line ( line : ĠString ): ĠMy Processing Result Ġ{ ĊĠĠĠ Ġval ĠcontentType Ġ= Ġdefine ContentType ( line ) ĊĠĠĠ Ġval Ġapplicable Ġ= Ġis Applicable ( line ) ĊĠĠĠ Ġreturn ĠMy Processing Result ( contentType , Ġapplicable , Ġnull ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġdefine ContentType ( line : ĠString ): ĠProcess OutputType Ġ{ ĊĠĠĠ Ġreturn Ġwhen Ġ{ ĊĠĠĠĠĠ Ġrejected Validation Types . any Ġ{ Ġline . contains ( it . description ) Ġ} Ġ-> ĠProcess OutputType . STD ERR ĊĠĠĠĠĠ Ġelse Ġ-> ĠProcess OutputType . STDOUT ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ Ċ }