// Ġ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 . workspace . j ps Ċ Ċ import Ġcom . intellij . configuration Store . Store Util Ċ import Ġcom . intellij . openapi . command . Write Command Action Ċ import Ġcom . intellij . openapi . module . Empty Module Type Ċ import Ġcom . intellij . openapi . module . Module Manager Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . roots . Module Root Manager Ċ import Ġcom . intellij . openapi . roots . Order Root Type Ċ import Ġcom . intellij . openapi . roots . libraries . Library Ċ import Ġcom . intellij . openapi . roots . libraries . Library Tables Registrar Ċ import Ġcom . intellij . openapi . util . J DOM Util Ċ import Ġcom . intellij . test Framework . Application Rule Ċ import Ġcom . intellij . test Framework . Disposable Rule Ċ import Ġcom . intellij . test Framework . Temporary Directory Ċ import Ġcom . intellij . workspace . api .* Ċ import Ġcom . intellij . workspace . ide . Workspace Model Ċ import Ġcom . intellij . workspace . ide . Workspace Model ChangeListener Ċ import Ġcom . intellij . workspace . ide . Workspace Model Topics Ċ import Ġcom . intellij . workspace . legacy Bridge . intellij . Legacy Bridge Module Ċ import Ġorg . junit . Assert .* Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġjava . io . File Ċ Ċ class ĠLegacy Bridge Project Library Test Ġ{ ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġvar Ġapplication Ġ= ĠApplication Rule () ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġvar Ġtemporary Directory Rule Ġ= ĠTemporary Directory () ĊĊĠ Ġ@ Rule ĊĠ Ġ@ Jvm Field ĊĠ Ġvar Ġdis posable Rule Ġ= ĠDis posable Rule () ĊĊĠ Ġprivate Ġlateinit Ġvar Ġproject : ĠProject ĊĠ Ġprivate Ġlateinit Ġvar Ġevents : ĠMutable List < Entity Change < Library Entity >> ĊĊĠ Ġ@ Before ĊĠ Ġfun Ġprepare Project () Ġ{ ĊĠĠĠ Ġproject Ġ= Ġcreate Empty Test Project ( temporary Directory Rule , Ġdis posable Rule ) ĊĊĠĠĠ Ġevents Ġ= Ġmutable ListOf () ĊĠĠĠ Ġval Ġmessage Bus Connection Ġ= Ġproject . message Bus . connect ( dis posable Rule . dis posable ) ĊĠĠĠ ĠWorkspace Model Topics . getInstance ( project ). subscribe Immediate ly ( message Bus Connection , Ġobject Ġ: ĠWorkspace Model ChangeListener Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġchanged ( event : ĠEntity Store Changed ) Ġ{ ĊĠĠĠĠĠĠĠ Ġevents . addAll ( event . get Changes ( Library Entity :: class . java )) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibrary Ġrename `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval Ġlibrary Name Ġ= Ġ" ant - lib " ĊĠĠĠ Ġval Ġnew Library Name Ġ= Ġ" maven - lib " ĊĠĠĠ Ġval Ġlibrary Ġ= Ġcreate Project Library ( library Name ) ĊĠĠĠ ĠassertEquals ( 2 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Added Event ( events [ 0 ], Ġlibrary Name ) ĊĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( library Name )) ĊĊĠĠĠ Ġrename Project Library ( library Name , Ġnew Library Name ) ĊĠĠĠ ĠassertNull ( project Library Table . get Library ByName ( library Name )) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( new Library Name )) ĊĠĠĠ ĠassertSame ( library , Ġproject Library Table . get Library ByName ( new Library Name )) ĊĠĠĠ ĠassertEquals ( 3 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Re placed Event ( events [ 2 ], Ġlibrary Name , Ġnew Library Name ) ĊĊĠĠĠ Ġrename Project Library ( new Library Name , Ġlibrary Name ) ĊĠĠĠ ĠassertNull ( project Library Table . get Library ByName ( new Library Name )) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( library Name )) ĊĠĠĠ ĠassertSame ( library , Ġproject Library Table . get Library ByName ( library Name )) ĊĠĠĠ ĠassertEquals ( 4 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Re placed Event ( events [ 3 ], Ġnew Library Name , Ġlibrary Name ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibraries Ġname Ġsw apping `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval Ġinter im Library Name Ġ= Ġ" tmp - lib " ĊĠĠĠ Ġval Ġant Library Name Ġ= Ġ" ant - lib " ĊĠĠĠ Ġval Ġmaven Library Name Ġ= Ġ" maven - lib " ĊĠĠĠ Ġval Ġant Library Ġ= Ġcreate Project Library ( ant Library Name ) ĊĠĠĠ Ġ// ĠCheck Ġevents Ġfrom Ġlistener Ġone Ġevent Ġfor Ġcreate Ġanother Ġfor Ġadd Ġroots ĊĠĠĠ ĠassertEquals ( 2 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Added Event ( events [ 0 ], Ġant Library Name ) ĊĊĠĠĠ Ġval Ġmaven Library Ġ= Ġcreate Project Library ( maven Library Name ) ĊĠĠĠ Ġ// ĠCheck Ġevents Ġfrom Ġlistener ĊĠĠĠ ĠassertEquals ( 4 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Added Event ( events [ 2 ], Ġmaven Library Name ) ĊĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( ant Library Name )) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( maven Library Name )) ĊĊĠĠĠ Ġ// ĠRename Ġlibrary Ġto Ġintermediate Ġname ĊĠĠĠ Ġrename Project Library ( ant Library Name , Ġinter im Library Name ) ĊĠĠĠ ĠassertNull ( project Library Table . get Library ByName ( ant Library Name )) ĊĠĠĠ ĠassertEquals ( 5 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Re placed Event ( events [ 4 ], Ġant Library Name , Ġinter im Library Name ) ĊĊĠĠĠ Ġ// ĠSwap Ġname Ġfor Ġthe Ġfirst Ġlibrary ĊĠĠĠ Ġrename Project Library ( maven Library Name , Ġant Library Name ) ĊĠĠĠ ĠassertNull ( project Library Table . get Library ByName ( maven Library Name )) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( ant Library Name )) ĊĠĠĠ ĠassertSame ( maven Library , Ġproject Library Table . get Library ByName ( ant Library Name )) ĊĠĠĠ ĠassertEquals ( 6 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Re placed Event ( events [ 5 ], Ġmaven Library Name , Ġant Library Name ) ĊĊĠĠĠ Ġ// ĠSwap Ġname Ġfor Ġthe Ġsecond Ġlibrary ĊĠĠĠ Ġrename Project Library ( inter im Library Name , Ġmaven Library Name ) ĊĠĠĠ ĠassertNull ( project Library Table . get Library ByName ( inter im Library Name )) ĊĠĠĠ ĠassertNotNull ( project Library Table . get Library ByName ( ant Library Name )) ĊĠĠĠ ĠassertSame ( ant Library , Ġproject Library Table . get Library ByName ( maven Library Name )) ĊĠĠĠ ĠassertEquals ( 7 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Re placed Event ( events [ 6 ], Ġinter im Library Name , Ġmaven Library Name ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibraries Ġname Ġsw apping Ġin Ġone Ġtransaction `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval Ġant Library Name Ġ= Ġ" ant - lib " ĊĠĠĠ Ġval Ġmaven Library Name Ġ= Ġ" maven - lib " ĊĠĠĠ Ġval Ġgro ovy Library Name Ġ= Ġ" groovy - lib " ĊĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĠĠĠ Ġproject Library Table . modifiable Model . let Ġ{ Ġproject Lib TableModel Ġ-> ĊĠĠĠĠĠ Ġval Ġant Library Ġ= Ġproject Lib TableModel . create Library ( ant Library Name ) ĊĠĠĠĠĠ Ġval Ġmaven Library Ġ= Ġproject Lib TableModel . create Library ( maven Library Name ) ĊĊĠĠĠĠĠ Ġvar Ġant Library Model Ġ= Ġant Library . modifiable Model ĊĠĠĠĠĠ Ġant Library Model . add Root ( File ( project . basePath , Ġ"$ ant Library Name . jar "). path , ĠOrder Root Type . CLASSES ) ĊĠĠĠĠĠ Ġant Library Model . add Root ( File ( project . basePath , Ġ"$ ant Library Name - sources . jar "). path , ĠOrder Root Type . SOURCES ) ĊĠĠĠĠĠ Ġant Library Model . name Ġ= Ġgro ovy Library Name ĊĠĠĠĠĠ Ġant Library Model . commit () ĊĊĠĠĠĠĠ Ġval Ġmaven Library Model Ġ= Ġmaven Library . modifiable Model ĊĠĠĠĠĠ Ġmaven Library Model . add Root ( File ( project . basePath , Ġ"$ maven Library Name . jar "). path , ĠOrder Root Type . CLASSES ) ĊĠĠĠĠĠ Ġmaven Library Model . add Root ( File ( project . basePath , Ġ"$ maven Library Name - sources . jar "). path , ĠOrder Root Type . SOURCES ) ĊĠĠĠĠĠ Ġmaven Library Model . name Ġ= Ġant Library Name ĊĠĠĠĠĠ Ġmaven Library Model . commit () ĊĊĠĠĠĠĠ Ġant Library Model Ġ= Ġant Library . modifiable Model ĊĠĠĠĠĠ Ġant Library Model . name Ġ= Ġmaven Library Name ĊĠĠĠĠĠ Ġant Library Model . commit () ĊĊĠĠĠĠĠ Ġproject Lib TableModel . commit () ĊĠĠĠ Ġ} ĊĊĠĠĠ ĠassertEquals ( 2 , Ġproject Library Table . libraries . size ) ĊĠĠĠ Ġval Ġant Library Ġ= Ġproject Library Table . libraries . find Ġ{ Ġit . name Ġ== Ġant Library Name Ġ} !! ĊĠĠĠ ĠassertEquals ( ant Library Name , Ġant Library . name ) ĊĠĠĠ ĠassertTrue ( ant Library . get Urls ( Order Root Type . CLASSES )[ 0 ]. contains ( maven Library Name )) ĊĊĠĠĠ Ġval Ġmaven Library Ġ= Ġproject Library Table . libraries . find Ġ{ Ġit . name Ġ== Ġmaven Library Name Ġ} !! ĊĠĠĠ ĠassertEquals ( maven Library Name , Ġmaven Library . name ) ĊĠĠĠ ĠassertTrue ( maven Library . get Urls ( Order Root Type . CLASSES )[ 0 ]. contains ( ant Library Name )) ĊĊĠĠĠ ĠassertEquals ( 2 , Ġevents . size ) ĊĠĠĠ ĠStore Util . save Documents And Project Settings ( project ) ĊĠĠĠ ĠassertTrue ( check Library Class Root On Disk ( ant Library Name , Ġ"$ maven Library Name . jar ")) ĊĠĠĠ ĠassertTrue ( check Library Class Root On Disk ( maven Library Name , Ġ"$ ant Library Name . jar ")) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibrary Ġalready Ġexists Ġexception `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval Ġlibrary Name Ġ= Ġ" ant - lib " ĊĠĠĠ Ġval Ġanother Library Name Ġ= Ġ" maven - lib " ĊĠĠĠ Ġcreate Project Library ( library Name ) ĊĠĠĠ ĠassertEquals ( 2 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Added Event ( events [ 0 ], Ġlibrary Name ) ĊĊĠĠĠ Ġ// ĠCatch Ġexception Ġduring Ġlibrary Ġcreation ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġcreate Project Library ( library Name ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġcatch Ġ( e : ĠIllegalStateException ) Ġ{ ĊĠĠĠĠĠ ĠassertEquals (" Project Ġlibrary Ġnamed Ġ$ library Name Ġalready Ġexists ", Ġe . message ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// ĠCheck Ġevent Ġwas Ġnot Ġpublished ĊĠĠĠ ĠassertEquals ( 2 , Ġevents . size ) ĊĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĠĠĠ ĠassertEquals ( 1 , Ġproject Library Table . libraries . size ) ĊĠĠĠ Ġcreate Project Library ( another Library Name ) ĊĠĠĠ ĠassertEquals ( 2 , Ġproject Library Table . libraries . size ) ĊĠĠĠ ĠassertEquals ( 4 , Ġevents . size ) ĊĠĠĠ Ġcheck Library Added Event ( events [ 2 ], Ġanother Library Name ) ĊĊĠĠĠ Ġ// ĠCatch Ġexception Ġduring Ġlibrary Ġrename ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġrename Project Library ( another Library Name , Ġlibrary Name ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġcatch Ġ( e : ĠIllegalStateException ) Ġ{ ĊĠĠĠĠĠ ĠassertEquals (" Library Ġnamed Ġ$ library Name Ġalready Ġexists ", Ġe . message ) ĊĠĠĠ Ġ} ĊĠĠĠ ĠassertEquals ( 2 , Ġproject Library Table . libraries . size ) ĊĠĠĠ ĠassertEquals ( 4 , Ġevents . size ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibrary Ġcreation Ġin Ġone Ġtransaction `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval Ġlibrary Name Ġ= Ġ" ant - lib " ĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĠĠĠ Ġproject Library Table . modifiable Model . let Ġ{ ĊĠĠĠĠĠ Ġval Ġlibrary Ġ= Ġit . create Library ( library Name ) ĊĠĠĠĠĠ Ġlibrary . modifiable Model . let Ġ{ Ġm Lib Ġ-> ĊĠĠĠĠĠĠĠ Ġm Lib . add Root ( File ( project . basePath , Ġ"$ library Name . jar "). path , ĠOrder Root Type . CLASSES ) ĊĠĠĠĠĠĠĠ Ġm Lib . add Root ( File ( project . basePath , Ġ"$ library Name - sources . jar "). path , ĠOrder Root Type . SOURCES ) ĊĠĠĠĠĠĠĠ Ġm Lib . commit () ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġit . commit () ĊĠĠĠ Ġ} ĊĠĠĠ ĠassertEquals ( 1 , Ġevents . size ) ĊĠĠĠ Ġval Ġevent Ġ= Ġevents [ 0 ] ĊĠĠĠ ĠassertTrue ( event Ġis ĠEntity Change . Added ) ĊĠĠĠ Ġval Ġlibrary Entity Ġ= Ġ( event Ġas ĠEntity Change . Added ). entity ĊĠĠĠ ĠassertEquals ( library Name , Ġlibrary Entity . name ) ĊĠĠĠ ĠassertTrue ( library Entity . table Id Ġis ĠLibrary Table Id . Project Library Table Id ) ĊĠĠĠ ĠassertEquals ( 2 , Ġlibrary Entity . roots . size ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibrary Ġrename Ġas Ġmodule Ġdependency `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval Ġant Library Name Ġ= Ġ" ant - lib " ĊĠĠĠ Ġval Ġmaven Library Name Ġ= Ġ" maven - lib " ĊĠĠĠ Ġval Ġi pr File Ġ= ĠFile ( project . project FilePath !! ) ĊĠĠĠ Ġval Ġmodule File Ġ= ĠFile ( project . basePath , Ġ" build . im l ") ĊĊĠĠĠ Ġval Ġlibrary Ġ= Ġcreate Project Library ( ant Library Name , Ġwith Roots Ġ= Ġfalse ) ĊĠĠĠ ĠStore Util . save Documents And Project Settings ( project ) ĊĠĠĠ ĠassertTrue ( ipr File . read Text (). contains ( ant Library Name )) ĊĊĠĠĠ Ġval Ġmodule Ġ= ĠModule Manager . getInstance ( project ). modifiable Model . let Ġ{ ĊĠĠĠĠĠ Ġval Ġmodule Ġ= Ġit . new Module ( module File . path , ĠEmpty Module Type . getInstance (). id ) Ġas ĠLegacy Bridge Module ĊĠĠĠĠĠ Ġit . commit () ĊĠĠĠĠĠ Ġmodule ĊĠĠĠ Ġ} ĊĠĠĠ ĠModule Root Manager . getInstance ( module ). modifiable Model . let Ġ{ ĊĠĠĠĠĠ Ġit . add Library Entry ( library ) ĊĠĠĠĠĠ Ġit . commit () ĊĠĠĠ Ġ} ĊĠĠĠ ĠStore Util . save Documents And Project Settings ( project ) ĊĠĠĠ ĠassertTrue ( module File . read Text (). contains ( ant Library Name )) ĊĠĠĠ ĠassertFalse ( module File . read Text (). contains ( maven Library Name )) ĊĊĠĠĠ Ġlibrary . modifiable Model . let Ġ{ ĊĠĠĠĠĠ Ġit . name Ġ= Ġmaven Library Name ĊĠĠĠĠĠ Ġit . commit () ĊĠĠĠ Ġ} ĊĠĠĠ ĠStore Util . save Documents And Project Settings ( project ) ĊĠĠĠ Ġ// ĠCheck Ġproject Ġfile Ġcontains Ġnew Ġname Ġof Ġlib ĊĠĠĠ ĠassertTrue ( ipr File . read Text (). contains ( maven Library Name )) ĊĠĠĠ ĠassertFalse ( ipr File . read Text (). contains ( ant Library Name )) ĊĠĠĠ Ġ// ĠCheck Ġmodule Ġfile Ġcontains Ġnew Ġname Ġof Ġlib Ġtoo ĊĠĠĠ ĠassertTrue ( module File . read Text (). contains ( maven Library Name )) ĊĠĠĠ ĠassertFalse ( module File . read Text (). contains ( ant Library Name )) ĊĊĠĠĠ Ġval Ġmodule Dependency Item Ġ= ĠWorkspace Model . getInstance ( project ). entity Store . current ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. entities ( Module Entity :: class . java ). first () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. dependencies . last () ĊĠĠĠ ĠassertTrue ( module Dependency Item Ġis ĠModule Dependency Item . Export able . Library Dependency ) ĊĠĠĠ Ġval Ġlibrary Dependency Ġ= Ġmodule Dependency Item Ġas ĠModule Dependency Item . Export able . Library Dependency ĊĠĠĠ ĠassertEquals ( maven Library Name , Ġlibrary Dependency . library . name ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġ` test Ġproject Ġlibrary Ġadd Ġto Ġmodule Ġdisposed `() Ġ= ĠWrite Command Action . run Write Command Action ( project ) Ġ{ ĊĠĠĠ Ġval ĠmoduleName Ġ= Ġ" build " ĊĠĠĠ Ġval Ġant Library Name Ġ= Ġ" ant - lib " ĊĊĠĠĠ Ġval Ġlibrary Ġ= Ġcreate Project Library ( ant Library Name , Ġwith Roots Ġ= Ġfalse ) ĊĠĠĠ Ġval Ġmodule File Ġ= ĠFile ( project . basePath , Ġ"$ moduleName . im l ") ĊĠĠĠ Ġval Ġmodule Ġ= ĠModule Manager . getInstance ( project ). modifiable Model . let Ġ{ Ġmodule Model Ġ-> ĊĠĠĠĠĠ Ġval Ġmodule Ġ= Ġmodule Model . new Module ( module File . path , ĠEmpty Module Type . getInstance (). id ) Ġas ĠLegacy Bridge Module ĊĠĠĠĠĠ Ġmodule Model . commit () ĊĠĠĠĠĠ Ġmodule ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġmodule Root Manager Ġ= ĠModule Root Manager . getInstance ( module ) ĊĠĠĠ Ġmodule Root Manager . modifiable Model . let Ġ{ Ġroot Model Ġ-> ĊĠĠĠĠĠ Ġroot Model . add Library Entry ( library ) ĊĠĠĠĠĠ Ġroot Model . dispose () ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġmodule Dependencies Ġ= ĠWorkspace Model . getInstance ( project ). entity Store . current ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. entities ( Module Entity :: class . java ). first () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. dependencies ĊĠĠĠ ĠassertEquals ( 1 , Ġmodule Dependencies . size ) ĊĠĠĠ ĠassertTrue ( module Dependencies [ 0 ] Ġis ĠModule Dependency Item . Module Source Dependency ) ĊĠĠĠ ĠStore Util . save Documents And Project Settings ( project ) ĊĠĠĠ ĠassertFalse ( module File . read Text (). contains ( ant Library Name )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcheck Library Added Event ( event : ĠEntity Change < Library Entity >, Ġlibrary Name : ĠString ) Ġ{ ĊĠĠĠ ĠassertTrue ( event Ġis ĠEntity Change . Added ) ĊĠĠĠ Ġval Ġlibrary Entity Ġ= Ġ( event Ġas ĠEntity Change . Added ). entity ĊĠĠĠ ĠassertEquals ( library Name , Ġlibrary Entity . name ) ĊĠĠĠ ĠassertTrue ( library Entity . table Id Ġis ĠLibrary Table Id . Project Library Table Id ) ĊĠĠĠ ĠassertEquals ( 0 , Ġlibrary Entity . roots . size ) ĊĠĠĠ Ġcheck Library Disk State ( library Name ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcheck Library Re placed Event ( event : ĠEntity Change < Library Entity >, Ġold Library Name : ĠString , Ġnew Library Name : ĠString ) Ġ{ ĊĠĠĠ ĠassertTrue ( event Ġis ĠEntity Change . Re placed ) ĊĠĠĠ Ġval Ġreplaced Ġ= Ġevent Ġas ĠEntity Change . Re placed ĊĠĠĠ Ġval Ġnew Entity Ġ= Ġreplaced . new Entity ĊĠĠĠ Ġval Ġold Entity Ġ= Ġreplaced . old Entity ĊĠĠĠ ĠassertEquals ( old Library Name , Ġold Entity . name ) ĊĠĠĠ ĠassertTrue ( old Entity . table Id Ġis ĠLibrary Table Id . Project Library Table Id ) ĊĠĠĠ ĠassertEquals ( new Library Name , Ġnew Entity . name ) ĊĠĠĠ ĠassertTrue ( new Entity . table Id Ġis ĠLibrary Table Id . Project Library Table Id ) ĊĠĠĠ ĠassertEquals ( 2 , Ġnew Entity . roots . size ) ĊĠĠĠ Ġcheck Library Disk State ( new Library Name , Ġold Library Name ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcheck Library Disk State ( current Library Name : ĠString , Ġprevious Library Name : ĠString Ġ= Ġ"") Ġ{ ĊĠĠĠ Ġval Ġi pr File Ġ= ĠFile ( project . project FilePath !! ) ĊĠĠĠ ĠStore Util . save Documents And Project Settings ( project ) ĊĠĠĠ Ġval Ġlibraries List Ġ= ĠJ DOM Util . load ( ipr File ). getChildren (" component ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. first Ġ{ Ġit . getAttribute (" name ") !!. value Ġ== Ġ" library Table " Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. getChildren (" library ") ĊĠĠĠ ĠassertTrue ( libraries List . find Ġ{ Ġit . getAttribute (" name ") !!. value Ġ== Ġcurrent Library Name Ġ} Ġ!= Ġnull ) ĊĠĠĠ ĠassertTrue ( libraries List . find Ġ{ Ġit . getAttribute (" name ") !!. value Ġ== Ġprevious Library Name Ġ} Ġ== Ġnull ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcheck Library Class Root On Disk ( library Name : ĠString , Ġclass FileName : ĠString ): ĠBoolean Ġ{ ĊĠĠĠ Ġreturn ĠJ DOM Util . load ( File ( project . project FilePath !! )). getChildren (" component ") ĊĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. first Ġ{ Ġit . getAttribute (" name ") !!. value Ġ== Ġ" library Table " Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . getChildren (" library ") ?. find Ġ{ Ġit . getAttribute (" name ") !!. value Ġ== Ġlibrary Name Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . getChild ( Order Root Type . CLASSES . name ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . getChild (" root ") ĊĠĠĠĠĠĠĠĠĠĠĠĠ Ġ? . getAttribute (" url ") ?. value ?. contains ( class FileName ) Ġ?: Ġfalse ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate Project Library ( library Name : ĠString , Ġwith Roots : ĠBoolean Ġ= Ġtrue ): ĠLibrary Ġ{ ĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĠĠĠ Ġval Ġlibrary Ġ= Ġproject Library Table . create Library ( library Name ) ĊĊĠĠĠ Ġif Ġ( with Roots ) Ġ{ ĊĠĠĠĠĠ Ġlibrary . modifiable Model . let Ġ{ ĊĠĠĠĠĠĠĠ Ġit . add Root ( File ( project . basePath , Ġ"$ library Name . jar "). path , ĠOrder Root Type . CLASSES ) ĊĠĠĠĠĠĠĠ Ġit . add Root ( File ( project . basePath , Ġ"$ library Name - sources . jar "). path , ĠOrder Root Type . SOURCES ) ĊĠĠĠĠĠĠĠ Ġit . commit () ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġlibrary ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġrename Project Library ( old Library Name : ĠString , Ġnew Library Name : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġproject Library Table Ġ= ĠLibrary Tables Registrar . getInstance (). get Library Table ( project ) ĊĊĠĠĠ Ġproject Library Table . get Library ByName ( old Library Name )?. modifiable Model ?. let Ġ{ ĊĠĠĠĠĠ Ġit . name Ġ= Ġnew Library Name ĊĠĠĠĠĠ Ġit . commit () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }