From a9f4f2dd96c9c92e21be7c4732b59f4aa2958005 Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 20 May 2019 11:31:46 +0200 Subject: [PATCH] akka.build.version property, #26958 (#26959) * akka.build.version property, #26958 * and use timestamped snapshot version if "timestamp" is passed in * to support publishing snapshots with same version for Scala 2.12 and 2.13 with +publish * remove stampVersion plugin, since it's no longer needed * store currentDateTime in system property * to survive reloads --- build.sbt | 1 - project/AkkaBuild.scala | 24 +++++++++++++++++++++-- project/TimeStampede.scala | 39 -------------------------------------- 3 files changed, 22 insertions(+), 42 deletions(-) delete mode 100644 project/TimeStampede.scala diff --git a/build.sbt b/build.sbt index c1ba77c501..4e3b0cb6e8 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,6 @@ import akka.{ AutomaticModuleName, CopyrightHeaderForBuild, ParadoxSupport, Scal enablePlugins( UnidocRoot, - TimeStampede, UnidocWithPrValidation, NoPublish, CopyrightHeader, diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index 4d012e3b4c..d44c408f36 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -6,6 +6,9 @@ package akka import java.io.{FileInputStream, InputStreamReader} import java.util.Properties +import java.time.format.DateTimeFormatter +import java.time.ZonedDateTime +import java.time.ZoneOffset import sbt.Keys._ import sbt._ @@ -21,14 +24,31 @@ object AkkaBuild { lazy val buildSettings = Dependencies.Versions ++ Seq( organization := "com.typesafe.akka", - // use the same value as in the build scope, so it can be overriden by stampVersion + // use the same value as in the build scope version := (version in ThisBuild).value) + lazy val currentDateTime = { + // storing the first accessed timestamp in system property so that it will be the + // same when build is reloaded or when using `+`. + // `+` actually doesn't re-initialize this part of the build but that may change in the future. + sys.props.getOrElseUpdate("akka.build.timestamp", + DateTimeFormatter + .ofPattern("yyyyMMdd-HHmmss") + .format(ZonedDateTime.now(ZoneOffset.UTC))) + } + + def akkaVersion: String = { + sys.props.getOrElse("akka.build.version", "2.6-SNAPSHOT") match { + case "timestamp" => s"2.6-$currentDateTime" // used when publishing timestamped snapshots + case v => v + } + } + lazy val rootSettings = Release.settings ++ UnidocRoot.akkaSettings ++ Protobuf.settings ++ Seq( parallelExecution in GlobalScope := System.getProperty("akka.parallelExecution", parallelExecutionByDefault.toString).toBoolean, - version in ThisBuild := "2.6-SNAPSHOT" + version in ThisBuild := akkaVersion ) lazy val mayChangeSettings = Seq( diff --git a/project/TimeStampede.scala b/project/TimeStampede.scala deleted file mode 100644 index e6d829acb3..0000000000 --- a/project/TimeStampede.scala +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2009-2019 Lightbend Inc. - */ - -package akka - -import java.time.Instant -import java.time.LocalDateTime -import java.time.ZoneId -import java.time.format.DateTimeFormatter - -import sbt._ -import sbt.Keys._ - -object TimeStampede extends AutoPlugin { - - override def trigger = noTrigger - - override lazy val projectSettings = Seq( - commands += stampVersion) - - final val Snapshot = "-SNAPSHOT" - - def stampVersion = Command.command("stampVersion") { state => - val extracted = Project.extract(state) - extracted.appendWithSession(List(version in ThisBuild ~= stamp), state) - } - - def stamp(version: String): String = { - if (version endsWith Snapshot) (version stripSuffix Snapshot) + "-" + timestamp(System.currentTimeMillis) - else version - } - - val formatter = DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss") - - def timestamp(time: Long): String = { - formatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault())) - } -}