/* Ċ Ġ* ĠCopyright Ġ 2 0 0 0 - 2 0 1 2 ĠJetBrains Ġs . r . o . Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġorg . jetbrains . j ps . incremental . artifacts Ċ Ċ import Ġcom . intellij . openapi . application . ex . Path Manager Ex Ċ import Ġcom . intellij . openapi . util . io . File Util Ċ import Ġcom . intellij . util . Path Util Ċ import Ġcom . intellij . util . io . directory Content Ċ import Ġcom . intellij . util . io . zip File Ċ import Ġorg . jetbrains . j ps . builders . Compile Scope Test Builder Ċ import Ġorg . jetbrains . j ps . incremental . artifacts . Layout Element TestUtil . archive Ċ import Ġorg . jetbrains . j ps . incremental . artifacts . Layout Element TestUtil . root Ċ import Ġorg . jetbrains . j ps . incremental . messages . Build Message Ċ import Ġorg . jetbrains . j ps . model . java . Java Source Root Type Ċ import Ġorg . jetbrains . j ps . model . java . J ps Java Extension Service Ċ import Ġorg . jetbrains . j ps . util . J ps Path Util Ċ import Ġjava . io . Buffered OutputStream Ċ import Ġjava . io . File Ċ import Ġjava . io . File OutputStream Ċ import Ġjava . io . IOException Ċ import Ġjava . util . jar . Jar File Ċ import Ġjava . util . zip . CRC 3 2 Ċ import Ġjava . util . zip . Zip Entry Ċ import Ġjava . util . zip . Zip File Ċ import Ġjava . util . zip . Zip OutputStream Ċ Ċ /** Ċ Ġ* Ġ@ author Ġn ik Ċ Ġ*/ Ċ class ĠArtifact Builder Test Ġ: ĠArtifact Builder TestCase () Ġ{ ĊĠ Ġfun Ġtest File Copy () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). file Copy ( create File (" file . txt ", Ġ" foo "))) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġfile (" file . txt ", Ġ" foo ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Dir () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( ĊĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" abc . txt ")) ĊĠĠĠĠĠĠĠĠĠ Ġ. dir (" dir ") ĊĠĠĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" xxx . txt ", Ġ" bar ")) ĊĠĠĠ Ġ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" abc . txt ") ĊĠĠĠĠĠ Ġdir (" dir ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" xxx . txt ", Ġ" bar ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Archive () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( ĊĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠ Ġ. archive (" xxx . zip ") ĊĠĠĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" X . class ", Ġ" data ")) ĊĠĠĠĠĠĠĠĠĠ Ġ. dir (" dir ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" Y . class ")) ĊĠĠĠ Ġ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġzip (" xxx . zip ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" X . class ", Ġ" data ") ĊĠĠĠĠĠĠĠ Ġdir (" dir ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġfile (" Y . class ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Two Dirs In Archive () Ġ{ ĊĠĠĠ Ġval Ġdir 1 Ġ= ĠPath Util . getParent Path ( Path Util . getParent Path ( create File (" dir 1 / a / x . txt "))) ĊĠĠĠ Ġval Ġdir 2 Ġ= ĠPath Util . getParent Path ( Path Util . getParent Path ( create File (" dir 2 / a / y . txt "))) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( ĊĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠ Ġ. archive (" a . jar ") ĊĠĠĠĠĠĠĠĠĠ Ġ. dir Copy ( dir 1 ) ĊĠĠĠĠĠĠĠĠĠ Ġ. dir Copy ( dir 2 ) ĊĠĠĠĠĠĠĠĠĠ Ġ. dir (" a "). file Copy ( create File (" z . txt ")) ĊĠĠĠ Ġ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġzip (" a . jar ") Ġ{ ĊĠĠĠĠĠĠĠ Ġdir (" a ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġfile (" x . txt ") ĊĠĠĠĠĠĠĠĠĠ Ġfile (" y . txt ") ĊĠĠĠĠĠĠĠĠĠ Ġfile (" z . txt ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Archive In Archive () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( ĊĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠ Ġ. archive (" a . jar ") ĊĠĠĠĠĠĠĠ Ġ. archive (" b . jar ") ĊĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" xxx . txt ", Ġ" foo ")) ĊĠĠĠ Ġ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġzip (" a . jar ") Ġ{ ĊĠĠĠĠĠĠĠ Ġzip (" b . jar ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġfile (" xxx . txt ", Ġ" foo ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Included Artifact () Ġ{ ĊĠĠĠ Ġval Ġincluded Ġ= Ġadd Artifact (" included ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" aaa . txt "))) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( ĊĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠ Ġ. dir (" dir ") ĊĠĠĠĠĠĠĠ Ġ. artifact ( included ) ĊĠĠĠĠĠĠĠ Ġ. end () ĊĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" bbb . txt ")) ĊĠĠĠ Ġ) ĊĠĠĠ Ġbuild All () ĊĊĠĠĠ Ġassert Output ( included , Ġdirectory Content Ġ{ Ġfile (" aaa . txt ") Ġ}) ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġdir (" dir ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" aaa . txt ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġfile (" bbb . txt ") ĊĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Merge Directories () Ġ{ ĊĠĠĠ Ġval Ġincluded Ġ= Ġadd Artifact (" included ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġroot (). dir (" dir "). file Copy ( create File (" aaa . class "))) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( ĊĠĠĠĠĠ Ġroot () ĊĠĠĠĠĠĠĠ Ġ. artifact ( included ) ĊĠĠĠĠĠĠĠ Ġ. dir (" dir ") ĊĠĠĠĠĠĠĠ Ġ. file Copy ( create File (" bbb . class "))) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġdir (" dir ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" aaa . class ") ĊĠĠĠĠĠĠĠ Ġfile (" bbb . class ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Copy Library () Ġ{ ĊĠĠĠ Ġval Ġlibrary Ġ= Ġadd Project Library (" lib ", Ġcreate File (" lib / a . jar ")) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). lib ( library )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġfile (" a . jar ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Module Output () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" src / A . java ", Ġ" public Ġclass ĠA Ġ{} ") ĊĠĠĠ Ġval Ġmodule Ġ= Ġadd Module (" a ", ĠPath Util . getParent Path ( file )) ĊĠĠĠ Ġval Ġartifact Ġ= Ġadd Artifact ( root (). module ( module )) ĊĊĠĠĠ Ġbuild Artifacts ( artifact ) ĊĠĠĠ Ġassert Output ( artifact , Ġdirectory Content Ġ{ Ġfile (" A . class ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Module Sources () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" src / A . java ", Ġ" class ĠA {} ") ĊĠĠĠ Ġval Ġtest File Ġ= Ġcreate File (" tests / AT est . java ", Ġ" class ĠA Test {} ") ĊĠĠĠ Ġval Ġm Ġ= Ġadd Module (" m ", ĠPath Util . getParent Path ( file )) ĊĠĠĠ Ġm . add Source Root ( J ps Path Util . path To Url ( Path Util . getParent Path ( test File )), ĠJava Source Root Type . TEST _ SOURCE ) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). module Source ( m )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" A . java ") ĊĠĠĠ Ġ}) ĊĊĠĠĠ Ġval Ġb Ġ= Ġcreate File (" src / B . java ", Ġ" class ĠB {} ") ĊĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" A . java ") ĊĠĠĠĠĠ Ġfile (" B . java ") ĊĠĠĠ Ġ}) ĊĊĠĠĠ Ġdelete ( b ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" A . java ") ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Module Sources With Package Prefix () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" src / A . java ", Ġ" class ĠA {} ") ĊĠĠĠ Ġval Ġm Ġ= Ġadd Module (" m ", ĠPath Util . getParent Path ( file )) ĊĠĠĠ Ġval Ġsource Root Ġ= Ġassert One Element ( m . source Roots ) ĊĠĠĠ Ġval Ġtyped Ġ= Ġsource Root . as Typed ( Java Source Root Type . SOURCE ) ĊĠĠĠ ĠassertNotNull ( typed ) ĊĠĠĠ Ġtyped !!. properties . package Prefix Ġ= Ġ" org . foo " ĊĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). module Source ( m )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġdir (" org ") Ġ{ ĊĠĠĠĠĠĠĠ Ġdir (" foo ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġfile (" A . java ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Copy Resources From Module Output () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" src / a . xml ", Ġ"") ĊĠĠĠ ĠJ ps Java Extension Service . getInstance (). get OrCreate Compiler Configuration ( my Project ). add Resource Pattern (" *. xml ") ĊĠĠĠ Ġval Ġmodule Ġ= Ġadd Module (" a ", ĠPath Util . getParent Path ( file )) ĊĠĠĠ Ġval Ġartifact Ġ= Ġadd Artifact ( root (). module ( module )) ĊĠĠĠ Ġbuild Artifacts ( artifact ) ĊĠĠĠ Ġassert Output ( artifact , Ġdirectory Content Ġ{ Ġfile (" a . xml ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Ignored File () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" a /. svn / a . txt ") ĊĠĠĠ Ġcreate File (" a / svn / b . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). parent Dir Copy ( Path Util . getParent Path ( file ))) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġdir (" svn ") Ġ{ Ġfile (" b . txt ") Ġ}}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Ignored File In Archive () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" a /. svn / a . txt ") ĊĠĠĠ Ġcreate File (" a / svn / b . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). parent Dir Copy ( Path Util . getParent Path ( file ))) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġzip (" a . jar ") Ġ{ Ġdir (" svn ") Ġ{ Ġfile (" b . txt ") }} }) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Copy Excluded Folder () Ġ{ ĊĠĠĠ Ġ// explicit ly Ġadded Ġexcluded Ġfiles Ġshould Ġbe Ġcopied Ġ( e . g . Ġcompile Ġoutput ) ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" xxx / excluded / a . txt ") ĊĠĠĠ Ġcreate File (" xxx / excluded / C VS ") ĊĠĠĠ Ġval Ġexcluded Ġ= ĠPath Util . getParent Path ( file ) ĊĠĠĠ Ġval Ġdir Ġ= ĠPath Util . getParent Path ( excluded ) ĊĊĠĠĠ Ġval Ġmodule Ġ= Ġadd Module (" my Module ") ĊĠĠĠ Ġmodule . content Roots List . add Url ( J ps Path Util . path To Url ( dir )) ĊĠĠĠ Ġmodule . exclude Roots List . add Url ( J ps Path Util . path To Url ( excluded )) ĊĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). dir Copy ( excluded )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġfile (" a . txt ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Copy Excluded File () Ġ{ ĊĠĠĠ Ġ// excluded Ġfiles Ġunder Ġnon - excluded Ġdirectory Ġshould Ġnot Ġbe Ġcopied ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" xxx / excluded / a . txt ") ĊĠĠĠ Ġcreate File (" xxx / b . txt ") ĊĠĠĠ Ġcreate File (" xxx / C VS ") ĊĠĠĠ Ġval Ġdir Ġ= ĠPath Util . getParent Path ( Path Util . getParent Path ( file )) ĊĊĠĠĠ Ġval Ġmodule Ġ= Ġadd Module (" my Module ") ĊĠĠĠ Ġmodule . content Roots List . add Url ( J ps Path Util . path To Url ( dir )) ĊĠĠĠ Ġmodule . exclude Roots List . add Url ( J ps Path Util . path To Url ( Path Util . getParent Path ( file ))) ĊĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). dir Copy ( dir )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġfile (" b . txt ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Extract Directory () Ġ{ ĊĠĠĠ Ġval Ġjar File Ġ= Ġcreate X Jar File () ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). dir (" dir "). extract ed Dir ( jar File , Ġ"/ dir ")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġdir (" dir ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" file . txt ", Ġ" text ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġ@ Throws ( IOException :: class ) ĊĠ Ġfun Ġtest Extract Directory From Excluded Jar () Ġ{ ĊĠĠĠ Ġval Ġjar Path Ġ= Ġcreate File (" dir / lib / j . jar ") ĊĠĠĠ Ġval Ġlib Dir Ġ= ĠFile ( get OrCreate Project Dir (), Ġ" dir / lib ") ĊĠĠĠ Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġzip (" j . jar ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" a . txt ", Ġ" a ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}. generate ( lib Dir ) ĊĠĠĠ Ġval Ġmodule Ġ= Ġadd Module (" m ") ĊĠĠĠ Ġval Ġlib DirPath Ġ= ĠFile Util . to System In dependent Name ( lib Dir . absolute Path ) ĊĠĠĠ Ġmodule . content Roots List . add Url ( J ps Path Util . path To Url ( Path Util . getParent Path ( lib DirPath ))) ĊĠĠĠ Ġmodule . exclude Roots List . add Url ( J ps Path Util . path To Url ( lib DirPath )) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). extract ed Dir ( jar Path , Ġ"")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" a . txt ", Ġ" a ") ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Pack Extract ed Directory () Ġ{ ĊĠĠĠ Ġval Ġzip Path Ġ= Ġcreate X Jar File () ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). archive (" a . jar "). extract ed Dir ( zip Path , Ġ"/ dir ")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġzip (" a . jar ") Ġ{ ĊĠĠĠĠĠ Ġfile (" file . txt ", Ġ" text ") ĊĠĠĠ Ġ}}) ĊĠ Ġ} ĊĊĠ Ġfun Ġ` test Ġno Ġduplicated Ġdirectory Ġentries Ġfor Ġextracted Ġdirectory Ġpacked Ġinto ĠJ AR Ġfile `() Ġ{ ĊĠĠĠ Ġval Ġzip Path Ġ= Ġcreate X Jar File () ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). archive (" a . jar "). extract ed Dir ( zip Path , Ġ"")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ ĠZip File ( File ( a . output Path , Ġ" a . jar ")). use Ġ{ ĊĠĠĠĠĠ ĠassertNotNull ( it . getEntry (" dir / ")) ĊĠĠĠĠĠ ĠassertNull ( it . getEntry (" dir // ")) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġcreate X Jar File (): ĠString Ġ{ ĊĠĠĠ Ġval Ġzip File Ġ= Ġzip File Ġ{ ĊĠĠĠĠĠ Ġdir (" dir ") Ġ{ ĊĠĠĠĠĠĠĠ Ġfile (" file . txt ", Ġ" text ") ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}. generate In TempDir () ĊĠĠĠ Ġreturn ĠFile Util . to System In dependent Name ( zip File . absolute Path ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Self In cluding Artifact () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). file Copy ( create File (" a . txt "))) ĊĠĠĠ ĠLayout Element TestUtil . add Artifact To Layout ( a , Ġa ) ĊĠĠĠ Ġassert Build Failed ( a ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Circular In clusion () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). file Copy ( create File (" a . txt "))) ĊĠĠĠ Ġval Ġb Ġ= Ġadd Artifact (" b ", Ġroot (). file Copy ( create File (" b . txt "))) ĊĠĠĠ ĠLayout Element TestUtil . add Artifact To Layout ( a , Ġb ) ĊĠĠĠ ĠLayout Element TestUtil . add Artifact To Layout ( b , Ġa ) ĊĠĠĠ Ġassert Build Failed ( a ) ĊĠĠĠ Ġassert Build Failed ( b ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Artifact Containing Self In cluding Artifact () Ġ{ ĊĠĠĠ Ġval Ġc Ġ= Ġadd Artifact (" c ", Ġroot (). file Copy ( create File (" c . txt "))) ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). artifact ( c ). file Copy ( create File (" a . txt "))) ĊĠĠĠ ĠLayout Element TestUtil . add Artifact To Layout ( a , Ġa ) ĊĠĠĠ Ġval Ġb Ġ= Ġadd Artifact (" b ", Ġroot (). artifact ( a ). file Copy ( create File (" b . txt "))) ĊĊĠĠĠ Ġbuild Artifacts ( c ) ĊĠĠĠ Ġassert Build Failed ( b ) ĊĠĠĠ Ġassert Build Failed ( a ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Artifact Containing Self In cluding Artifact Without Output () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġroot (). file Copy ( create File (" a . txt "))) ĊĠĠĠ ĠLayout Element TestUtil . add Artifact To Layout ( a , Ġa ) ĊĠĠĠ Ġval Ġb Ġ= Ġadd Artifact (" b ", Ġroot (). artifact ( a )) ĊĠĠĠ Ġa . output Path Ġ= Ġnull ĊĊĠĠĠ Ġassert Build Failed ( b ) ĊĠ Ġ} ĊĊĠ Ġ// IDE A - 7 3 8 9 3 ĊĠ Ġ@ Throws ( IOException :: class ) ĊĠ Ġfun Ġtest Manifest File Is First Entry () Ġ{ ĊĠĠĠ Ġval Ġfirst File Ġ= Ġcreate File (" src / A . txt ") ĊĠĠĠ Ġval Ġmanifest File Ġ= Ġcreate File (" src / MAN IFEST . MF ") ĊĠĠĠ Ġval Ġlast File Ġ= Ġcreate File (" src / Z . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). dir (" META - INF ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. file Copy ( first File ). file Copy ( manifest File ). file Copy ( last File )) ĊĠĠĠ Ġbuild Artifacts ( a ) ĊĠĠĠ Ġval Ġjar Path Ġ= Ġa . output Path !! Ġ+ Ġ"/ a . jar " ĊĠĠĠ Ġval Ġjar File Ġ= ĠJar File ( File ( jar Path )) ĊĠĠĠ Ġjar File . use Ġ{ ĊĠĠĠĠĠ Ġval Ġentries Ġ= Ġit . entries () ĊĠĠĠĠĠ ĠassertTrue ( entries . hasMore Elements ()) ĊĠĠĠĠĠ Ġval Ġfirst Entry Ġ= Ġentries . nextElement () ĊĠĠĠĠĠ ĠassertEquals ( Jar File . MAN IFEST _ NAME , Ġfirst Entry . name ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Throws ( IOException :: class ) ĊĠ Ġfun Ġtest Preserve Compression Method For Entry Extract ed From One Archive And Packed Into Another () Ġ{ ĊĠĠĠ Ġval Ġpath Ġ= Ġcreate File (" data / a . jar ") ĊĠĠĠ Ġval Ġoutput Ġ= ĠZip OutputStream ( Buffered OutputStream ( File OutputStream ( File ( path )))) ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġval Ġentry Ġ= ĠZip Entry (" a . txt ") ĊĠĠĠĠĠ Ġval Ġtext Ġ= Ġ" text ". toByteArray () ĊĠĠĠĠĠ Ġentry . method Ġ= ĠZip Entry . STO RED ĊĠĠĠĠĠ Ġentry . size Ġ= Ġtext . size . to Long () ĊĠĠĠĠĠ Ġval Ġcrc 3 2 Ġ= ĠCRC 3 2 () ĊĠĠĠĠĠ Ġcrc 3 2 . update ( text ) ĊĠĠĠĠĠ Ġentry . crc Ġ= Ġcrc 3 2 . value ĊĠĠĠĠĠ Ġoutput . put Next Entry ( entry ) ĊĠĠĠĠĠ Ġoutput . write ( text ) ĊĠĠĠĠĠ Ġoutput . close Entry () ĊĠĠĠ Ġ} ĊĠĠĠ Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠ Ġe . printStackTrace () ĊĠĠĠ Ġ} ĊĠĠĠ Ġfinally Ġ{ ĊĠĠĠĠĠ Ġoutput . close () ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" b . jar "). extract ed Dir ( path , Ġ"")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġzip (" b . jar ") Ġ{ Ġfile (" a . txt ", Ġ" text ") Ġ}}) ĊĊĠĠĠ Ġval Ġjar Path Ġ= Ġa . output Path !! Ġ+ Ġ"/ b . jar " ĊĠĠĠ Ġval Ġzip File Ġ= ĠZip File ( File ( jar Path )) ĊĠĠĠ Ġzip File . use Ġ{ ĊĠĠĠĠĠ Ġval Ġentry Ġ= Ġit . getEntry (" a . txt ") ĊĠĠĠĠĠ ĠassertNotNull ( entry ) ĊĠĠĠĠĠ ĠassertEquals ( Zip Entry . STO RED , Ġentry . method ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Pro per ly Report Value With Invalid Crc In Re packed File () Ġ{ ĊĠĠĠ Ġval Ġcorrupted Jar Ġ= ĠPath Manager Ex . find File Under Community Home ( ĊĠĠĠĠĠ Ġ" j ps / j ps - builders / testData / output / cor rupted Jar / incorrect - crc . jar ") !!. absolute Path ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). extract ed Dir ( cor rupted Jar , Ġ"")) ĊĠĠĠ Ġval Ġresult Ġ= Ġdo Build ( Compile Scope Test Builder . rebuild (). artifacts ( a )) ĊĠĠĠ Ġresult . assert Failed () ĊĠĠĠ Ġval Ġmessage Ġ= Ġresult . get Messages ( Build Message . Kind . ERROR ). first () ĊĠĠĠ ĠassertTrue ( message . message Text , Ġmessage . message Text . contains (" incorrect - crc . jar ")); ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Build Module Before Artifact If Some Directory Inside Module Output Is Copied To Artifact () Ġ{ ĊĠĠĠ Ġval Ġsrc Ġ= ĠPath Util . getParent Path ( Path Util . getParent Path ( create File (" src / x / A . java ", Ġ" package Ġx ; Ġclass ĠA {} "))) ĊĠĠĠ Ġval Ġmodule Ġ= Ġadd Module (" m ", Ġsrc ) ĊĠĠĠ Ġval Ġoutput Ġ= ĠJ ps Java Extension Service . getInstance (). getOutput Directory ( module , Ġfalse ) ĊĠĠĠ Ġval Ġartifact Ġ= Ġadd Artifact ( root (). dir Copy ( File ( output , Ġ" x "). absolute Path )) ĊĠĠĠ Ġrebuild All Modules And Artifacts () ĊĠĠĠ Ġassert Output ( module , Ġdirectory Content Ġ{ Ġdir (" x ") Ġ{ Ġfile (" A . class ") Ġ}}) ĊĠĠĠ Ġassert Output ( artifact , Ġdirectory Content Ġ{ Ġfile (" A . class ") Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Clear Output On Rebuild () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" d / a . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). parent Dir Copy ( file )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġcreate File In Artifact Output ( a , Ġ" b . txt ") ĊĠĠĠ Ġbuild All And Assert Up ToDate () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" a . txt ") ĊĠĠĠĠĠ Ġfile (" b . txt ") ĊĠĠĠ Ġ}) ĊĊĠĠĠ Ġrebuild All Modules And Artifacts () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġfile (" a . txt ") ĊĠĠĠĠĠ Ġfile (" b . txt ") ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Delete Only OutputFile On Rebuild For Archive Artifact () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" a . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). file Copy ( file )) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġcreate File In Artifact Output ( a , Ġ" b . txt ") ĊĠĠĠ Ġbuild All And Assert Up ToDate () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġzip (" a . jar ") Ġ{ Ġfile (" a . txt ") Ġ} ĊĠĠĠĠĠ Ġfile (" b . txt ") ĊĠĠĠ Ġ}) ĊĊĠĠĠ Ġrebuild All Modules And Artifacts () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ ĊĠĠĠĠĠ Ġzip (" a . jar ") Ġ{ Ġfile (" a . txt ") Ġ} ĊĠĠĠĠĠ Ġfile (" b . txt ") ĊĠĠĠ Ġ}) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest DoNot Create Empty Archive () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" dir / a . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). parent Dir Copy ( file )) ĊĠĠĠ Ġdelete ( file ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Empty Output ( a ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest DoNot Create Empty Archive Inside Archive () Ġ{ ĊĠĠĠ Ġval Ġfile Ġ= Ġcreate File (" dir / a . txt ") ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). archive (" inner . jar "). parent Dir Copy ( file )) ĊĠĠĠ Ġdelete ( file ) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Empty Output ( a ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest DoNot Create Empty Archive From Extract ed Directory () Ġ{ ĊĠĠĠ Ġval Ġjar File Ġ= Ġcreate X Jar File () ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact (" a ", Ġarchive (" a . jar "). dir (" dir "). extract ed Dir ( jar File , Ġ"/ xxx / ")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Empty Output ( a ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Extract Non Ex istent Jar File () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( root (). extract ed Dir (" this - file - does - not - exist . jar ", Ġ"/ ")) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Empty Output ( a ) ĊĠ Ġ} ĊĊĠ Ġfun Ġtest Re pack Non Ex istent Jar File () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġadd Artifact ( archive (" a . jar "). extract ed Dir (" this - file - does - not - exist . jar ", Ġ"/ "). file Copy ( create File (" a . txt "))) ĊĠĠĠ Ġbuild All () ĊĠĠĠ Ġassert Output ( a , Ġdirectory Content Ġ{ Ġzip (" a . jar ") Ġ{ file (" a . txt ") }}) ĊĠ Ġ} Ċ } Ċ