Skip to content

Commit

Permalink
Merge pull request #12 from hmrc/BDOG-519
Browse files Browse the repository at this point in the history
BDOG-519 Cross compile for sbt 0.13 and 1.3
  • Loading branch information
bennetimo authored Dec 2, 2019
2 parents 5a2b797 + 04d5eff commit 0c0c27a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
sudo: false
language: scala
scala:
- 2.10.5
- 2.10.7
jdk:
- oraclejdk7
- openjdk8
cache:
directories:
- '$HOME/.ivy2/cache'
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ help you track down where a build came from.

## How to use it ##

### Sbt 1.x

Since major version 6, this plugin is cross compiled for sbt 1.x (specifically 1.3.4).

| Sbt version | Plugin version |
| ----------- | -------------- |
| `<= 0.13.x` | `any` |
| `>= 1.x` | `>= 6.x` |

Add the following to your `project/plugins.sbt`:

```scala
Expand Down
14 changes: 7 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ lazy val root = Project(pluginName, base = file("."))
.enablePlugins(SbtAutoBuildPlugin, SbtGitVersioning, SbtArtifactory)
.settings(
sbtPlugin := true,
majorVersion := 5,
majorVersion := 6,
makePublicallyAvailableOnBintray := true,
targetJvm := "jvm-1.7",
organization := "uk.gov.hmrc",
scalaVersion := "2.10.5",
scalaVersion := "2.10.7", //Pinned to 2.10 while on sbt 0.13 to match ^ cross build inferred version
crossSbtVersions := Vector("0.13.18", "1.3.4"),
libraryDependencies ++=
Seq(
"com.github.nscala-time" %% "nscala-time" % "2.2.0",
"org.eclipse.jgit" % "org.eclipse.jgit" % "3.6.1.201501031845-r",
"org.scalatest" %% "scalatest" % "2.2.4" % Test,
"org.pegdown" % "pegdown" % "1.5.0" % Test
"com.github.nscala-time" %% "nscala-time" % "2.22.0",
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.11.9.201909030838-r",
"org.scalatest" %% "scalatest" % "3.1.0" % Test,
"com.vladsch.flexmark" % "flexmark-all" % "0.35.10" % Test
)
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.17
sbt.version=0.13.18
8 changes: 5 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
resolvers += Resolver.url("hmrc-sbt-plugin-releases",
url("https://dl.bintray.com/hmrc/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "1.13.0")
resolvers += Resolver.bintrayRepo("hmrc", "releases")

addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "1.7.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "1.16.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "0.12.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-git-versioning" % "2.0.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "0.21.0")
9 changes: 4 additions & 5 deletions src/main/scala/uk/gov/hmrc/gitstamp/GitStamp.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 HM Revenue & Customs
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,15 +23,15 @@ import org.eclipse.jgit.lib.{ObjectId, Repository}
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.joda.time.format.ISODateTimeFormat._
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._

object GitStamp{

def gitStamp: Map[String, String] = gitStamp(new FileRepositoryBuilder().readEnvironment.findGitDir.build)

def gitStamp(repository: Repository): Map[String, String] = {
val git = new Git(repository)
val headId = repository.getRef(HEAD).getObjectId
val headId = repository.exactRef(HEAD).getObjectId
val headIdStr = ObjectId.toString(headId)
val describe = Option(git.describe().call()).getOrElse(headIdStr)
val headRev = headCommit(git, headId)
Expand All @@ -58,8 +58,7 @@ object GitStamp{
}

private def headCommit(git: Git, headId: ObjectId): Option[RevCommit] = {
git.log().add(headId).setMaxCount(1).call().toSeq.headOption
git.log().add(headId).setMaxCount(1).call().asScala.toSeq.headOption
}

private def committerName: (RevCommit) => String = _.getCommitterIdent.getName
}
13 changes: 5 additions & 8 deletions src/main/scala/uk/gov/hmrc/gitstamp/GitStampPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 HM Revenue & Customs
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,12 +20,9 @@ import sbt.Keys._
import sbt.Package.ManifestAttributes
import sbt._

import scala.collection.JavaConversions._
object GitStampPlugin extends AutoPlugin {

object GitStampPlugin extends Plugin {
val gitStampSettings: Seq[Def.Setting[Task[scala.Seq[PackageOption]]]] =
Seq(packageOptions += ManifestAttributes(GitStamp.gitStamp.toSeq: _*))

val gitStampSettings =
Seq(packageOptions <+= (packageOptions in Compile, packageOptions in packageBin) map { (a, b) =>
ManifestAttributes(GitStamp.gitStamp.toSeq: _*)
})
}
}
7 changes: 4 additions & 3 deletions src/test/scala/uk/gov/hmrc/gitstamp/GitStampSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 HM Revenue & Customs
* Copyright 2019 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,10 @@

package uk.gov.hmrc.gitstamp

import org.scalatest.{Matchers, WordSpec}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class GitStampSpec extends WordSpec with Matchers{
class GitStampSpec extends AnyWordSpec with Matchers{

"Git repo information" in {
val info = GitStamp.gitStamp.toString
Expand Down

0 comments on commit 0c0c27a

Please sign in to comment.