Skip to content

Commit

Permalink
Merge pull request #16 from hmrc/update
Browse files Browse the repository at this point in the history
Update sbt and dependencies from Java 21
  • Loading branch information
colin-lamed authored Jan 17, 2024
2 parents 17642e7 + eeb465c commit 9f3f7c3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ lib_managed/*

**/codekit-config.json
nohup.out
.metals/
.vscode/
7 changes: 3 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

Expand Down Expand Up @@ -178,15 +178,15 @@ Apache License
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2014 HM Revenue & Customs
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -199,4 +199,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

26 changes: 11 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import uk.gov.hmrc.DefaultBuildSettings.targetJvm

val pluginName = "sbt-git-stamp"

lazy val root = Project(pluginName, base = file("."))
.enablePlugins(SbtAutoBuildPlugin, SbtGitVersioning, SbtArtifactory)
lazy val root = Project("sbt-git-stamp", file("."))
.settings(
sbtPlugin := true,
majorVersion := 6,
makePublicallyAvailableOnBintray := true,
organization := "uk.gov.hmrc",
scalaVersion := "2.12.10",
crossSbtVersions := Vector("0.13.18", "1.3.4"),
libraryDependencies ++=
sbtPlugin := true,
majorVersion := 6,
isPublicArtefact := true,
organization := "uk.gov.hmrc",
scalaVersion := "2.12.18",
libraryDependencies ++=
Seq(
"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
"com.github.nscala-time" %% "nscala-time" % "2.22.0",
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.11.9.201909030838-r",
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"com.vladsch.flexmark" % "flexmark-all" % "0.64.8" % Test
)
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.4
sbt.version=1.9.7
11 changes: 3 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
resolvers += Resolver.url("hmrc-sbt-plugin-releases",
url("https://dl.bintray.com/hmrc/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

resolvers += Resolver.bintrayRepo("hmrc", "releases")
resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2")
resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "2.2.0")

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

addSbtPlugin("uk.gov.hmrc" % "sbt-artifactory" % "1.0.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.19.0")
38 changes: 18 additions & 20 deletions src/main/scala/uk/gov/hmrc/gitstamp/GitStamp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,40 @@ 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.JavaConverters._
import scala.jdk.CollectionConverters._

object GitStamp{

def gitStamp: Map[String, String] = gitStamp(new FileRepositoryBuilder().readEnvironment.findGitDir.build)
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.exactRef(HEAD).getObjectId
val git = new Git(repository)
val headId = repository.exactRef(HEAD).getObjectId
val headIdStr = ObjectId.toString(headId)
val describe = Option(git.describe().call()).getOrElse(headIdStr)
val headRev = headCommit(git, headId)
val describe = Option(git.describe().call()).getOrElse(headIdStr)
val headRev = headCommit(git, headId)

Map ("Build-Date" -> dateTime.print(DateTime.now),
"Git-Branch" -> repository.getBranch,
Map(
"Build-Date" -> dateTime.print(DateTime.now),
"Git-Branch" -> repository.getBranch,
"Git-Repo-Is-Clean" -> repoIsClean(git),
"Git-Head-Rev" -> headIdStr,
"Git-Head-Rev" -> headIdStr,
"Git-Commit-Author" -> commitAuthorName(headRev),
"Git-Commit-Date" -> commitDateTime(headRev),
"Git-Describe" -> describe)
"Git-Commit-Date" -> commitDateTime(headRev),
"Git-Describe" -> describe
)
}

private def repoIsClean(git: Git): String = {
private def repoIsClean(git: Git): String =
git.status.call.isClean.toString
}

private def commitDateTime(headRev: Option[RevCommit]): String = {
private def commitDateTime(headRev: Option[RevCommit]): String =
dateTime.print(headRev.map(_.getCommitTime.toLong * 1000).getOrElse(0L))
}

private def commitAuthorName(headRev: Option[RevCommit]): String = {
private def commitAuthorName(headRev: Option[RevCommit]): String =
headRev.map(_.getCommitterIdent.getName).getOrElse("")
}

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

}
18 changes: 9 additions & 9 deletions src/test/scala/uk/gov/hmrc/gitstamp/GitStampSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ package uk.gov.hmrc.gitstamp
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

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

"Git repo information" in {
val info = GitStamp.gitStamp.toString
info.contains("Build-Date") shouldBe true
info.contains("Git-Branch") shouldBe true
info.contains("Git-Repo-Is-Clean") shouldBe true
info.contains("Git-Head-Rev") shouldBe true
info.contains("Git-Commit-Author") shouldBe true
info.contains("Git-Commit-Date") shouldBe true
info.contains("Git-Describe") shouldBe true
val info = GitStamp.gitStamp
info should contain key "Build-Date"
info should contain key "Git-Branch"
info should contain key "Git-Repo-Is-Clean"
info should contain key "Git-Head-Rev"
info should contain key "Git-Commit-Author"
info should contain key "Git-Commit-Date"
info should contain key "Git-Describe"
}
}

0 comments on commit 9f3f7c3

Please sign in to comment.