/* Ċ Ġ* ĠCopyright Ġ 2 0 1 0 - 2 0 1 8 ĠJetBrains Ġs . r . o . Ġand ĠKotlin ĠProgramming ĠLanguage Ġcontributors . Ċ Ġ* ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe Ġlicense / LICENSE . txt Ġfile . Ċ Ġ*/ Ċ Ċ package Ġorg . jetbrains . kotlin . codegen Ċ Ċ import Ġorg . jetbrains . kotlin . cli . common . messages . Message Collector Ċ import Ġorg . jetbrains . kotlin . cli . jvm . compiler . Environment Config Files Ċ import Ġorg . jetbrains . kotlin . cli . jvm . compiler . Kotlin Core Environment Ċ import Ġorg . jetbrains . kotlin . script . load Script ing Plugin Ċ import Ġorg . jetbrains . kotlin . script . util . script Compilation Classpath From Context Or St lib Ċ import Ġorg . jetbrains . kotlin . script ing . configuration . configure Script Definitions Ċ import Ġorg . jetbrains . kotlin . test . Configuration Kind Ċ import Ġorg . jetbrains . kotlin . test . Test J dk Kind Ċ import Ġorg . jetbrains . kotlin . utils . Path Util Ċ import Ġorg . jetbrains . kotlin . utils . Path Util . K OT LIN _ SCRIPT ING _ COMMON _ JAR Ċ import Ġorg . jetbrains . kotlin . utils . Path Util . K OT LIN _ SCRIPT ING _ COMPILER _ IMPL _ JAR Ċ import Ġorg . jetbrains . kotlin . utils . Path Util . K OT LIN _ SCRIPT ING _ COMPILER _ PLUGIN _ JAR Ċ import Ġorg . jetbrains . kotlin . utils . Path Util . K OT LIN _ SCRIPT ING _ JVM _ JAR Ċ import Ġjava . io . File Ċ import Ġkotlin . reflect . K Class Ċ import Ġkotlin . script . experimental . annotations . Kotlin Script ĊĊ Ċ class ĠCustom Script Code gen Test Ġ: ĠCode gen TestCase () Ġ{ ĊĊĠĠĠ Ġfun Ġtest Annotated Definition () Ġ{ ĊĠĠĠĠĠĠĠ Ġcreate Script Test Environment (" org . jetbrains . kotlin . codegen . Test Script With Annotated Base Class ") ĊĠĠĠĠĠĠĠ Ġload Script (" val Ġx Ġ= Ġ 1 ") ĊĠĠĠĠĠĠĠ Ġval Ġres Ġ= Ġgenerate Script Class () ĊĠĠĠĠĠĠĠ ĠassertNull ( res . safe Get Annotation ( Kotlin Script :: class )) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( res . safe Get Annotation ( My Script Class Annotation :: class )) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( res . get Constructor (). safe Get Annotation ( My Script Constructor Annotation :: class )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġgenerate Script Class (): ĠClass < *> Ġ= Ġgenerate Class (" Script Test ") ĊĊĠĠĠ Ġprivate Ġfun Ġload Script ( text : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġmy Files Ġ= ĠCode gen Test Files . create (" script Test . k ts ", Ġtext , Ġmy Environment . project ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcreate Script Test Environment ( var arg Ġscript Definitions : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( my Environment Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠIllegalStateException (" must Ġnot Ġset Ġup Ġmy Environment Ġtwice ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġadditional Dependencies Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġscript Compilation Classpath From Context Or St lib (" tests - common ", Ġ" kotlin - stdlib ") Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠFile ( Test Script With Re ceiv ers :: class . java . protection Domain . code Source . location . to URI (). path ) Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwith ( Path Util . kotlin Paths For Dist Directory ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠarrayOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠK OT LIN _ SCRIPT ING _ COMPILER _ PLUGIN _ JAR , ĠK OT LIN _ SCRIPT ING _ COMPILER _ IMPL _ JAR , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠK OT LIN _ SCRIPT ING _ COMMON _ JAR , ĠK OT LIN _ SCRIPT ING _ JVM _ JAR ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ). map NotNull Ġ{ ĠFile ( lib Path , Ġit ). also Ġ{ ĠassertTrue ("$ it Ġnot Ġfound ", Ġit . exists ()) Ġ} Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġconfiguration Ġ= Ġcreate Configuration ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration Kind . ALL , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠTest J dk Kind . MOCK _ JDK , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadditional Dependencies , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġempty List (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġempty List () ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( script Definitions . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfigure Script Definitions ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġscript Definitions . asList (), Ġconfiguration , Ġthis :: class . java . class Loader , ĠMessage Collector . NONE , Ġempty Map () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġload Script ing Plugin ( configuration ) ĊĊĠĠĠĠĠĠĠ Ġmy Environment Ġ= ĠKotlin Core Environment . create For Tests ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtest Root Disposable , Ġconfiguration , ĠEnvironment Config Files . JVM _ CONFIG _ FILES ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ Ċ } Ċ Ċ @ Suppress (" UN CHECK ED _ CAST ") Ċ private Ġfun ĠClass <* >. safe Get Annotation ( ann : ĠK Class < out ĠAnnotation >): ĠAnnotation ? Ġ= ĊĠĠĠ Ġget Annotation ( class Loader . load Class ( ann . qualified Name ) Ġas ĠClass < Annotation >) Ċ Ċ @ Suppress (" UN CHECK ED _ CAST ") Ċ private Ġfun Ġjava . lang . reflect . Constructor <* >. safe Get Annotation ( ann : ĠK Class < out ĠAnnotation >): ĠAnnotation ? Ġ= ĊĠĠĠ Ġget Annotation ( this . decl aring Class . class Loader . load Class ( ann . qualified Name ) Ġas ĠClass < Annotation >) Ċ Ċ @ Target ( Annotation Target . CLASS ) Ċ @ Retention ( Annotation Retention . RUNTIME ) Ċ annotation Ġclass ĠMy Script Class Annotation Ċ Ċ @ Target ( Annotation Target . CON STRUCTOR ) Ċ @ Retention ( Annotation Retention . RUNTIME ) Ċ annotation Ġclass ĠMy Script Constructor Annotation Ċ Ċ @ Suppress (" unused ") Ċ @ Kotlin Script Ċ @ My Script Class Annotation () Ċ abstract Ġclass ĠTest Script With Annotated Base Class Ġ@ My Script Constructor Annotation Ġconstructor () ĊĊ