Updated to support file output.
This commit is contained in:
		
							parent
							
								
									ab9f1502b7
								
							
						
					
					
						commit
						5cdcc022df
					
				
					 3 changed files with 28 additions and 2 deletions
				
			
		|  | @ -1 +1 @@ | |||
| sbt.version=1.9.9 | ||||
| sbt.version=1.10.0 | ||||
|  |  | |||
|  | @ -42,4 +42,17 @@ object CalVerKeys { | |||
|     "Dump the calculated version information." | ||||
|   ) | ||||
| 
 | ||||
|   /** SBT Setting that defines the filename for dumping the calculated CalVer to | ||||
|     * a file. | ||||
|     */ | ||||
|   lazy val calVerOutputFile = settingKey[Option[String]]( | ||||
|     "Name of the file where the calculated SemVer will be stored (if requested)." | ||||
|   ) | ||||
| 
 | ||||
|   /** Task which writes the calculated CalVer to a file. | ||||
|     */ | ||||
|   lazy val calVerWriteVersionToFile = taskKey[Unit]( | ||||
|     "Write the calculated CalVer to a file." | ||||
|   ) | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -1,5 +1,8 @@ | |||
| package gs | ||||
| 
 | ||||
| import java.nio.charset.StandardCharsets | ||||
| import java.nio.file.Files | ||||
| import java.nio.file.Paths | ||||
| import sbt._ | ||||
| 
 | ||||
| object CalVerPlugin extends AutoPlugin { | ||||
|  | @ -9,10 +12,13 @@ object CalVerPlugin extends AutoPlugin { | |||
| 
 | ||||
|   import autoImport._ | ||||
| 
 | ||||
|   val DefaultOutputFile: String = ".version" | ||||
| 
 | ||||
|   lazy val calVerDefaults: Seq[Setting[_]] = | ||||
|     Seq( | ||||
|       calVerReleasePattern    := Some(CalVer.Defaults.ReleasePattern), | ||||
|       calVerPreReleasePattern := Some(CalVer.Defaults.PreReleasePattern) | ||||
|       calVerPreReleasePattern := Some(CalVer.Defaults.PreReleasePattern), | ||||
|       calVerOutputFile        := Some(DefaultOutputFile) | ||||
|     ) | ||||
| 
 | ||||
|   override lazy val projectSettings: Seq[Setting[_]] = { | ||||
|  | @ -32,6 +38,13 @@ object CalVerPlugin extends AutoPlugin { | |||
|         val log = Keys.streams.value.log | ||||
|         log.info(s"[CalVer] Version: ${calVer.value}") | ||||
|         log.info(s"[CalVer] Pattern: ${calVerPattern.value}") | ||||
|       }, | ||||
|       calVerWriteVersionToFile := { | ||||
|         val outputFile = calVerOutputFile.value.getOrElse(DefaultOutputFile) | ||||
|         Files.write( | ||||
|           Paths.get(outputFile), | ||||
|           calVer.value.getBytes(StandardCharsets.UTF_8) | ||||
|         ) | ||||
|       } | ||||
|     ) | ||||
|   } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue