Skip to content

Commit

Permalink
Split out versioning.
Browse files Browse the repository at this point in the history
The windows version is used for the unix versions,
so can't have its computation only run when running on windows.
  • Loading branch information
adriaanm committed Jan 10, 2014
1 parent f37d7ad commit 969f16c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 42 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ useJGit
// For testing, the version may be overridden with -Dproject.version=...
versionWithGit

Versioning.settings

s3Settings

host in upload := "downloads.typesafe.com.s3.amazonaws.com"
Expand Down
17 changes: 0 additions & 17 deletions project/Unix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ object Unix {
},

// RPM Specific
version in Rpm := toRpmVersion((version in Windows).value),
name in Rpm := "scala",
rpmVendor := "typesafe",
rpmUrl := Some("http://github.com/scala/scala"),
Expand All @@ -94,7 +93,6 @@ object Unix {
},

// Debian Specific
version in Debian := toDebianVersion((version in Windows).value),
name in Debian := "scala",
debianPackageDependencies += "openjdk-6-jre | java6-runtime",
debianPackageDependencies += "libjansi-java",
Expand All @@ -106,19 +104,4 @@ object Unix {
// Hack so we use regular version, rather than debian version.
target in Debian := target.value / s"${(name in Debian).value}-${version.value}"
)

private def rpmBuild(version:String): String = version split "\\." match {
case Array(_,_,_, b) => b
case _ => "1"
}

private def toRpmVersion(version:String): String = version split "\\." match {
case Array(m,n,b,_*) => s"$m.$n.$b"
case _ => version
}

private def toDebianVersion(version:String): String = version split "\\." match {
case Array(m,n,b,z) => s"$m.$n.$b-$z"
case _ => version
}
}
50 changes: 50 additions & 0 deletions project/Versioning.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import sbt._
import sbt.Keys._

import com.typesafe.sbt.SbtNativePackager.{Windows, Debian, Rpm}

object Versioning {
def settings: Seq[Setting[_]] = Seq(
version in Windows := makeWindowsVersion(version.value),
version in Debian := toDebianVersion((version in Windows).value),
version in Rpm := toRpmVersion((version in Windows).value))

private def rpmBuild(version:String): String = version split "\\." match {
case Array(_,_,_, b) => b
case _ => "1"
}

private def toRpmVersion(version:String): String = version split "\\." match {
case Array(m,n,b,_*) => s"$m.$n.$b"
case _ => version
}

private def toDebianVersion(version:String): String = version split "\\." match {
case Array(m,n,b,z) => s"$m.$n.$b-$z"
case _ => version
}

// This is a complicated means to convert maven version numbers into monotonically increasing windows versions.
private def makeWindowsVersion(version: String): String = {
val Majors = new scala.util.matching.Regex("(\\d+).(\\d+).(\\d+)(-.*)?")
val Rcs = new scala.util.matching.Regex("(\\-\\d+)?\\-RC(\\d+)")
val Milestones = new scala.util.matching.Regex("(\\-\\d+)?\\-M(\\d+)")
val BuildNum = new scala.util.matching.Regex("\\-(\\d+)")

def calculateNumberFour(buildNum: Int = 0, rc: Int = 0, milestone: Int = 0) =
if(rc > 0 || milestone > 0) (buildNum)*400 + rc*20 + milestone
else (buildNum+1)*400 + rc*20 + milestone

version match {
case Majors(major, minor, bugfix, rest) => Option(rest) getOrElse "" match {
case Milestones(null, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(0,0,num.toInt)
case Milestones(bnum, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(bnum.drop(1).toInt,0,num.toInt)
case Rcs(null, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(0,num.toInt,0)
case Rcs(bnum, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(bnum.drop(1).toInt,num.toInt,0)
case BuildNum(bnum) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(bnum.toInt,0,0)
case _ => major + "." + minor + "." + bugfix + "." + calculateNumberFour(0,0,0)
}
case x => x
}
}
}
25 changes: 0 additions & 25 deletions project/Wix.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ object Wix {
wixProductId := "7606e6da-e168-42b5-8345-b08bf774cb30",
wixProductUpgradeId := "6061c134-67c7-4fb2-aff5-32b01a186968",
// wixProductComments := "Scala Programming language for use in Windows.",
version in Windows := makeWindowsVersion(version.value),

wixProductConfig := makeProductConfig((stagingDirectory in Universal).value, (stagingDirectory in UniversalDocs).value),
wixProductConfig <<= (wixProductConfig
Expand Down Expand Up @@ -106,28 +105,4 @@ object Wix {
<WixVariable Id="WixUILicenseRtf" Value={ licensePath }/>
</xml:group>
}

// This is a complicated means to convert maven version numbers into monotonically increasing windows versions.
private def makeWindowsVersion(version: String): String = {
val Majors = new scala.util.matching.Regex("(\\d+).(\\d+).(\\d+)(-.*)?")
val Rcs = new scala.util.matching.Regex("(\\-\\d+)?\\-RC(\\d+)")
val Milestones = new scala.util.matching.Regex("(\\-\\d+)?\\-M(\\d+)")
val BuildNum = new scala.util.matching.Regex("\\-(\\d+)")

def calculateNumberFour(buildNum: Int = 0, rc: Int = 0, milestone: Int = 0) =
if(rc > 0 || milestone > 0) (buildNum)*400 + rc*20 + milestone
else (buildNum+1)*400 + rc*20 + milestone

version match {
case Majors(major, minor, bugfix, rest) => Option(rest) getOrElse "" match {
case Milestones(null, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(0,0,num.toInt)
case Milestones(bnum, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(bnum.drop(1).toInt,0,num.toInt)
case Rcs(null, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(0,num.toInt,0)
case Rcs(bnum, num) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(bnum.drop(1).toInt,num.toInt,0)
case BuildNum(bnum) => major + "." + minor + "." + bugfix + "." + calculateNumberFour(bnum.toInt,0,0)
case _ => major + "." + minor + "." + bugfix + "." + calculateNumberFour(0,0,0)
}
case x => x
}
}
}

0 comments on commit 969f16c

Please sign in to comment.