// ĠCopyright Ġ 2 0 0 0 - 2 0 2 1 Ġ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 . compiler . artifacts Ċ Ċ import Ġcom . intellij . ide . project View . Presentation Data Ċ import Ġcom . intellij . openapi . application . Write Action Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . util . text . StringUtil Ċ import Ġcom . intellij . packaging . artifacts . Artifact Ċ import Ġcom . intellij . packaging . artifacts . Artifact Manager Ċ import Ġcom . intellij . packaging . elements . Composite Pack aging Element Ċ import Ġcom . intellij . packaging . elements . Pack aging Element Ċ import Ġcom . intellij . packaging . elements . Pack aging Element Factory Ċ import Ġcom . intellij . packaging . elements . Pack aging ElementType Ċ import Ġcom . intellij . packaging . impl . artifacts . Plain Artifact Type Ċ import Ġcom . intellij . packaging . ui . Artifact Editor Context Ċ import Ġcom . intellij . packaging . ui . Pack aging Element Presentation Ċ import Ġcom . intellij . test Framework . Application Rule Ċ import Ġcom . intellij . test Framework . Platform TestUtil Ċ import Ġcom . intellij . test Framework . rules . Project Model Rule Ċ import Ġcom . intellij . ui . Simple Text Attributes Ċ import Ġcom . intellij . util . xml b . annotations . Attribute Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Class Rule Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġjava . io . File Ċ import Ġjava . util . function . Supplier Ċ Ċ class ĠArtifact sWith Custom Elements Test Ġ{ ĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġval Ġproject Model Ġ= ĠProject Model Rule ( true ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` create Ġcustom Ġartifact `() Ġ{ ĊĠĠĠ Ġval Ġproject Ġ= Ġproject Model . project ĊĊĠĠĠ Ġval Ġartifact Manager Ġ= ĠArtifact Manager . getInstance ( project ) ĊĠĠĠ ĠWrite Action . run And Wait < RuntimeException > Ġ{ ĊĠĠĠĠĠ Ġval Ġartifact Ġ= Ġartifact Manager . add Artifact (" Artifact ", ĠPlain Artifact Type . getInstance (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPack aging Element Factory . getInstance (). create Artifact Root Element ()) ĊĠĠĠĠĠ Ġval Ġmod ifiable Model Ġ= Ġartifact Manager . create Mod ifiable Model () ĊĠĠĠĠĠ Ġval Ġmod ifiable Artifact Ġ= Ġmod ifiable Model . get OrCreate Mod ifiable Artifact ( artifact ) ĊĠĠĠĠĠ Ġmod ifiable Artifact . root Element . add Or Find Child ( My Pack aging Element (" My Data ")) ĊĠĠĠĠĠ Ġmod ifiable Model . commit () ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPlatform TestUtil . save Project ( project ) ĊĊĠĠĠ Ġassert Artifact File Text Equals ( ĊĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠ Ġ|< component Ġname =" Artifact Manager "> ĊĠĠĠĠĠĠĠ Ġ| Ġ Ġ< artifact Ġname =" Artifact "> ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠ Ġ< output - path >${ '$ '} PROJECT _ DIR ${ '$ ' }/ out / artifacts / Artifact </ output - path > ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠ Ġ< root Ġid =" root "> ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠĠĠ Ġ< element Ġid =" My Element " Ġdata =" My Data " Ġ/> ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠ Ġ</ root > ĊĠĠĠĠĠĠĠ Ġ| Ġ Ġ</ artifact > ĊĠĠĠĠĠĠĠ Ġ| </ component > """. trim Margin ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` modify Ġcustom Ġartifact `() Ġ{ ĊĠĠĠ Ġval Ġproject Ġ= Ġproject Model . project ĊĊĠĠĠ Ġval Ġartifact Manager Ġ= ĠArtifact Manager . getInstance ( project ) ĊĠĠĠ ĠWrite Action . run And Wait < RuntimeException > Ġ{ ĊĠĠĠĠĠ Ġval Ġartifact Ġ= Ġartifact Manager . add Artifact (" Artifact ", ĠPlain Artifact Type . getInstance (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPack aging Element Factory . getInstance (). create Artifact Root Element ()) ĊĠĠĠĠĠ Ġval Ġmod ifiable Model Ġ= Ġartifact Manager . create Mod ifiable Model () ĊĠĠĠĠĠ Ġval Ġmod ifiable Artifact Ġ= Ġmod ifiable Model . get OrCreate Mod ifiable Artifact ( artifact ) ĊĠĠĠĠĠ Ġmod ifiable Artifact . root Element . add Or Find Child ( My Pack aging Element (" My Data ")) ĊĠĠĠĠĠ Ġmod ifiable Model . commit () ĊĊĠĠĠĠĠ Ġval Ġmod ifiable Model 2 Ġ= Ġartifact Manager . create Mod ifiable Model () ĊĠĠĠĠĠ Ġval Ġmod ifiable Artifact 2 Ġ= Ġmod ifiable Model 2 . get OrCreate Mod ifiable Artifact ( artifact ) ĊĠĠĠĠĠ Ġval Ġpackaging Element Ġ= Ġmod ifiable Artifact 2 . root Element . children [ 0 ] Ġas ĠMy Pack aging Element ĊĠĠĠĠĠ Ġpackaging Element . data Ġ= Ġ" Another Data " ĊĠĠĠĠĠ Ġmod ifiable Model 2 . commit () ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠPlatform TestUtil . save Project ( project ) ĊĊĠĠĠ Ġassert Artifact File Text Equals ( ĊĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠ Ġ|< component Ġname =" Artifact Manager "> ĊĠĠĠĠĠĠĠ Ġ| Ġ Ġ< artifact Ġname =" Artifact "> ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠ Ġ< output - path >${ '$ '} PROJECT _ DIR ${ '$ ' }/ out / artifacts / Artifact </ output - path > ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠ Ġ< root Ġid =" root "> ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠĠĠ Ġ< element Ġid =" My Element " Ġdata =" Another Data " Ġ/> ĊĠĠĠĠĠĠĠ Ġ| ĠĠĠ Ġ</ root > ĊĠĠĠĠĠĠĠ Ġ| Ġ Ġ</ artifact > ĊĠĠĠĠĠĠĠ Ġ| </ component > """. trim Margin ()) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Artifact File Text Equals ( expected Text : ĠString ) Ġ{ ĊĠĠĠ ĠAssert . assertEquals ( StringUtil . convert Line Separ ators ( expected Text ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠString Util . convert Line Separ ators ( File ( project Model . base Project Dir . root , Ġ". idea / artifacts / Artifact . xml "). read Text ())) ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġ@ Jvm Field ĊĠĠĠ Ġ@ Class Rule ĊĠĠĠ Ġval Ġapp Rule Ġ= ĠApplication Rule () ĊĠ Ġ} Ċ } Ċ Ċ object ĠMy Pack aging ElementType Ġ: ĠPack aging ElementType < My Pack aging Element >(" My Element ", ĠSupplier Ġ{ Ġ" My Ġelement " Ġ}) Ġ{ ĊĠ Ġoverride Ġfun Ġcan Create ( context : ĠArtifact Editor Context , Ġartifact : ĠArtifact ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn Ġtrue ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġchoose And Create ( context : ĠArtifact Editor Context , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġartifact : ĠArtifact , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġparent : ĠComposite Pack aging Element < *> ): ĠList < Pack aging Element <* >> Ġ{ ĊĠĠĠ Ġreturn ĠlistOf ( My Pack aging Element ()) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġcreate Empty ( project : ĠProject ): ĠMy Pack aging Element Ġ{ ĊĠĠĠ Ġreturn ĠMy Pack aging Element () ĊĠ Ġ} Ċ } Ċ Ċ class ĠMy Pack aging Element (_ data : ĠString ?) Ġ: ĠPack aging Element < My Pack aging Element >( My Pack aging ElementType ) Ġ{ ĊĊĠ Ġconstructor () Ġ: Ġthis ( null ) ĊĊĠ Ġ@ Attribute (" data ") ĊĠ Ġvar Ġdata : ĠString ? Ġ= Ġ_ data ĊĊĠ Ġoverride Ġfun Ġcreate Presentation ( context : ĠArtifact Editor Context ): ĠPack aging Element Presentation Ġ{ ĊĠĠĠ Ġreturn Ġobject Ġ: ĠPack aging Element Presentation () Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġget Present able Name (): ĠString Ġ= Ġ" My Ġelement " ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġrender ( presentation Data : ĠPresentation Data , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmain Attributes : ĠSimple Text Attributes ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcomment Attributes : ĠSimple Text Attributes ?) Ġ{ ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġoverride Ġfun Ġget Weight (): ĠInt Ġ= Ġ 0 ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġis EqualTo ( element : ĠPack aging Element < *> ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn Ġelement Ġis ĠMy Pack aging Element Ġ&& Ġelement . data Ġ== Ġthis . data ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun ĠgetState (): ĠMy Pack aging Element Ġ{ ĊĠĠĠ Ġreturn Ġthis ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġload State ( state : ĠMy Pack aging Element ) Ġ{ ĊĠĠĠ Ġthis . data Ġ= Ġstate . data ĊĠ Ġ} Ċ } Ċ