package Ġcom . zi em sky . gradle . git _ semver _ release _ plugin Ċ Ċ import Ġorg . gradle . api . Action Ċ import Ġorg . gradle . api . Plugin Ċ import Ġorg . gradle . api . Project Ċ import Ġorg . gradle . api . execution . Task Execution Graph Listener Ċ import Ġorg . gradle . api . logging . Logger Ċ import Ġorg . gradle . kotlin . dsl . register Ċ Ċ class ĠGit Sem ver Release Plugin Ġ: ĠPlugin < Project > Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġroot Project : ĠProject ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrepo : ĠGit Repo ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlogger : ĠLogger ĊĊĠĠĠ Ġoverride Ġfun Ġapply ( project : ĠProject ) Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . root Project Ġ= Ġproject . root Project ĊĠĠĠĠĠĠĠ Ġthis . logger Ġ= Ġproject . logger ĊĠĠĠĠĠĠĠ Ġthis . repo Ġ= ĠGit Repo . at ( project . rootDir ) ĊĊĠĠĠĠĠĠĠ Ġrequire Max One Release Task Requested () ĊĊĠĠĠĠĠĠĠ Ġ// Ġtodo Ġhandle Ġversion Ġtag Ġon ĠHEAD : Ġ Ġ- Ġsee Ġrequire NoVersion Tag On Head ĊĊĠĠĠĠĠĠĠ Ġinitialise Version On Root Project () ĊĊĠĠĠĠĠĠĠ Ġincrement Project Version If Requested () ĊĊĠĠĠĠĠĠĠ Ġregister Tasks () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġregister Tasks () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġroot Project . tasks . register ( Git Sem ver Release Major Task . name , ĠGit Sem ver Release Major Task :: class ) ĊĊĠĠĠĠĠĠĠ Ġroot Project . tasks . register ( Git Sem ver Release Minor Task . name , ĠGit Sem ver Release Minor Task :: class ) ĊĊĠĠĠĠĠĠĠ Ġroot Project . tasks . register ( Git Sem ver Release Patch Task . name , ĠGit Sem ver Release Patch Task :: class ) ĊĊĠĠĠĠĠĠĠ Ġroot Project . tasks . register ( Git Sem ver Release Dev Task . name , ĠGit Sem ver Release Dev Task :: class ) ĊĊĠĠĠĠĠĠĠ Ġroot Project . tasks . register (" version Print ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdo Last Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreport Current Project Version () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġincrement Project Version If Requested () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġrelease Task Companion Ġ= Ġrequested Release Tasks Companion () Ġ?: ĠGit Sem ver Release Dev Task . Companion ĊĊĠĠĠĠĠĠĠ ĠProject Version Increment er ( root Project , Ġrepo ). execute ( release Task Companion ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrequested Release Tasks Companion () Ġ= Ġrequested Release Tasks Comp an ions (). single OrNull () ĊĊĠĠĠ Ġprivate Ġfun Ġrequested Release Tasks Comp an ions (): ĠList < Git Sem ver Release Task Companion > Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠALL _ RELEASE _ TASK _ COMP AN IONS . filter Ġ{ Ġis Task WithName Requested ( it . name ) Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġis Task WithName Requested ( candidate Task Name : ĠString ) Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġroot Project . gradle . start Parameter . task Names . contains ( candidate Task Name ) ĊĊĠĠĠ Ġprivate Ġfun Ġreport Current Project Version () Ġ= Ġlogger . quiet ("${ root Project . version }") ĊĊĠĠĠ Ġprivate Ġfun Ġinitialise Version On Root Project () Ġ{ ĊĠĠĠĠĠĠĠ Ġset Project Version ( current Git Version ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġset Project Version ( new Version : ĠProject Version ) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġroot Project . logger . info (" Root Ġproject 's Ġversion Ġis Ġ$ new Version ") ĊĊĠĠĠĠĠĠĠ Ġroot Project . version Ġ= Ġnew Version ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġcurrent Git Version (): ĠProject Version Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġversion TagName Ġ= Ġrepo . current Version ( VERSION _ TAG _ PREFIX ) ĊĊĠĠĠĠĠĠĠ Ġreturn ĠProject Version . from ( version TagName , Ġrepo . is Dirty ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġrequire Max One Release Task Requested () Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġrelease Tasks Selected For Execution Ġ= Ġrequested Release Tasks Comp an ions () ĊĊĠĠĠĠĠĠĠ Ġval Ġno More Than One Release Task Found Ġ= Ġrelease Tasks Selected For Execution . size Ġ<= Ġ 1 ĊĊĠĠĠĠĠĠĠ Ġrequire ( no More Than One Release Task Found ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrequested Release Tasks Names Ġ= Ġrelease Tasks Selected For Execution ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġtask Ġ-> Ġtask . name Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. join ToString (", Ġ") ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" At Ġmost Ġone Ġrelease Ġtask Ġcan Ġbe Ġrequested Ġat Ġany Ġgiven Ġtime ; Ġtasks Ġactually Ġrequested : Ġ$ requested Release Tasks Names " ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval ĠVERSION _ TAG _ PREFIX Ġ= Ġ" version @" ĠĠ Ġ// Ġtodo Ġmove ?, Ġmake Ġconfigurable ĊĊĠĠĠĠĠĠĠ Ġval ĠALL _ RELEASE _ TASK _ COMP AN IONS Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠGit Sem ver Release Major Task . Companion , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠGit Sem ver Release Minor Task . Companion , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠGit Sem ver Release Patch Task . Companion , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠGit Sem ver Release Dev Task . Companion ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ }