Skip to content

Commit

Permalink
Merge pull request #160 from brharrington/sbt-tweaks
Browse files Browse the repository at this point in the history
build updates
  • Loading branch information
brharrington committed Aug 7, 2015
2 parents 230560c + ee70b69 commit f1fe526
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
11 changes: 7 additions & 4 deletions project/Bintray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ object Bintray {

lazy val now = System.currentTimeMillis
lazy val isPullRequest = sys.env.getOrElse("TRAVIS_PULL_REQUEST", "false") != "false"
lazy val (user, pass) = {
if (isPullRequest) ("dummyUser", "dummyPass")
else (sys.env.getOrElse("bintrayUser", "missingUser"), sys.env.getOrElse("bintrayKey", "missingKey"))

private def get(k: String): String = {
if (isPullRequest) s"dummy$k" else sys.env.getOrElse(s"bintray$k", s"missing$k")
}

lazy val user = get("User")
lazy val pass = get("Key")

lazy val storeBintrayCredentials = taskKey[Unit]("store bintray credentials")

lazy val settings: Seq[Def.Setting[_]] = bintraySettings ++ Seq(
Expand All @@ -27,7 +31,6 @@ object Bintray {
Some("OJO" at s"https://oss.jfrog.org/oss-snapshot-local;build.timestamp=${now}/")
else
publishTo in bintray value
//Some("bintray" at s"https://api.bintray.com/${bintrayOrganization.value.get}/${bintrayRepository.value}/")
},

storeBintrayCredentials := {
Expand Down
1 change: 0 additions & 1 deletion project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ object BuildSettings {
val resolvers = Seq(
Resolver.mavenLocal,
Resolver.jcenterRepo,
DefaultMavenRepository,
"jfrog" at "http://oss.jfrog.org/oss-snapshot-local",
"rrd4j" at "https://raw.githubusercontent.com/brharrington/rrd4j/repo")

Expand Down
56 changes: 34 additions & 22 deletions project/GitVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,46 @@ import sbtrelease.Version
import com.typesafe.sbt.SbtGit._

object GitVersion {
lazy val now = new java.util.Date()
lazy val dateFormatter = {
val f = new java.text.SimpleDateFormat("yyyyMMdd.HHmmss")
f.setTimeZone(java.util.TimeZone.getTimeZone("UTC"))
f
// 0.1.x
private val versionBranch = """([0-9\.]+?)(\.x)?""".r

// v0.1.47-31-g230560c
// v0.1.47-20150807.161518-9
private val snapshotVersion = """v?([0-9\.]+)-(\d+)-([0-9a-z]+)""".r

// v0.1.47
private val releaseVersion = """v?([0-9\.]+)""".r

/**
* Needs to check for "false", don't assume it will ever be set to "true".
* http://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
*/
private def isPullRequest: Boolean = sys.env.getOrElse("TRAVIS_PULL_REQUEST", "false") != "false"

/**
* Bump the last git described version to use for the current snapshot. If it is a version branch
* and the prefix doesn't match, then it is the first snapshot for the branch so use the branch
* version to start with.
*/
private def toSnapshotVersion(branch: String, v: String): String = {
val v2 = Version(v).map(_.bump.string).getOrElse(v)
val suffix = "-SNAPSHOT"
branch match {
case versionBranch(b) if !v2.startsWith(b) =>
s"${Version(b).map(_.string).getOrElse(v2)}$suffix"
case _ =>
s"$v2$suffix"
}
}

lazy val settings: Seq[Def.Setting[_]] = Seq(
version in ThisBuild := {
val versionBranch = """([0-9\.]+?)(\.x)?""".r
val snapshotVersion = """v?([0-9\.]+)-(\d+)-([0-9a-z]+)""".r
val releaseVersion = """v?([0-9\.]+)""".r
val isPullRequest = sys.env.getOrElse("TRAVIS_PULL_REQUEST", "false") != "false"
val branch = GitKeys.gitReader.value.withGit(_.branches).headOption.getOrElse("unknown")
git.gitDescribedVersion.value getOrElse "0.1-SNAPSHOT" match {
case v if (isPullRequest) => s"0.0.0-PULLREQUEST"
case snapshotVersion(v, n, h) => {
val v2 = Version(v).map(_.bump.string).getOrElse(v)
val suffix = "-SNAPSHOT" //s"-${dateFormatter.format(now)}" //s".${"%02d".format(n.toInt)}-SNAPSHOT"
branch match {
case versionBranch(b) if (!v2.startsWith(b)) => {
s"${Version(b).map(_.string).getOrElse(v2)}${suffix}"
}
case _ => s"${v2}${suffix}"
}
}
case releaseVersion(v) => v
case v => v
case _ if isPullRequest => s"0.0.0-PULLREQUEST"
case snapshotVersion(v, _, _) => toSnapshotVersion(branch, v)
case releaseVersion(v) => v
case v => v
}
}
)
Expand Down
4 changes: 1 addition & 3 deletions project/sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -v
#!/bin/bash

# This script is used to launch sbt on developer workstations.

Expand All @@ -12,8 +12,6 @@ java \
-XX:+UseG1GC \
-Xms2g \
-Xmx2g \
-XX:PermSize=512m \
-XX:MaxPermSize=512m \
-XX:ReservedCodeCacheSize=128m \
-XX:+UseCodeCacheFlushing \
-Dsbt.boot.directory=${WORKSPACE:-$HOME}/.sbt \
Expand Down

0 comments on commit f1fe526

Please sign in to comment.