From 6a7bce95cd8ea99d2a7b960182953a1ee491b111 Mon Sep 17 00:00:00 2001 From: Adriaan Groenenboom Date: Mon, 7 Oct 2024 19:25:49 +0200 Subject: [PATCH 1/2] First steps to migrate to sbt 2.0.0-M2 --- build.sbt | 10 ++++++---- project/build.properties | 2 +- project/plugins.sbt | 2 +- .../com/github/sbt/git/ConsoleGitRunner.scala | 14 +++++++------ .../scala/com/github/sbt/git/GitPlugin.scala | 2 +- src/main/scala/com/github/sbt/git/JGit.scala | 20 +++++++++---------- .../git-versioning/find-tag-newest/test | 2 ++ src/sbt-test/git-versioning/find-tag/test | 2 ++ src/sbt-test/git-versioning/get-message/test | 2 ++ .../multi-module-project-use-describe/test | 2 ++ .../git-versioning/multi-module-project/test | 2 ++ .../git-versioning/no-base-version/test | 2 ++ .../git-versioning/uncommitted-signifier/test | 2 ++ .../use-describe-with-matching/test | 2 ++ src/sbt-test/git-versioning/use-describe/test | 2 ++ .../git-versioning/with-base-version/test | 2 ++ 16 files changed, 47 insertions(+), 23 deletions(-) diff --git a/build.sbt b/build.sbt index d563b68..5f499d6 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,5 @@ organization := "com.github.sbt" -sonatypeProfileName := "com.github.sbt" +//sonatypeProfileName := "com.github.sbt" name := "sbt-git" licenses := Seq(("BSD-2-Clause", url("https://opensource.org/licenses/BSD-2-Clause"))) description := "An sbt plugin that offers git features directly inside sbt" @@ -8,10 +8,11 @@ startYear := Some(2011) homepage := scmInfo.value map (_.browseUrl) scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-git"), "scm:git:git@github.com:sbt/sbt-git.git")) -crossSbtVersions := List("1.3.13") +//crossSbtVersions := List("1.3.13") -enablePlugins(GitVersioning, SbtPlugin) -git.baseVersion := "1.0" +enablePlugins(SbtPlugin) +//TODO: enablePlugins(GitVersioning, SbtPlugin) +//git.baseVersion := "1.0" libraryDependencies ++= Seq( "org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.3.202401111512-r", @@ -20,3 +21,4 @@ libraryDependencies ++= Seq( ) scriptedLaunchOpts += s"-Dproject.version=${version.value}" +scriptedBufferLog := false \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index 0b699c3..f8d382d 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.2 +sbt.version=2.0.0-M2 diff --git a/project/plugins.sbt b/project/plugins.sbt index a9dfc13..14d390c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1") +//addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1") diff --git a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala index a471e82..515f19a 100644 --- a/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala +++ b/src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala @@ -1,8 +1,10 @@ package com.github.sbt.git -import sbt._ -import Keys._ -import sys.process.{ Process, ProcessLogger } +import sbt.{internal, *} +import Keys.* +import sbt.internal.util.ConsoleAppender + +import sys.process.{Process, ProcessLogger} /** A mechanism of running git that simply shells out to the console. */ object ConsoleGitRunner extends GitRunner { @@ -17,15 +19,15 @@ object ConsoleGitRunner extends GitRunner { // in order to enable colors we trick git into thinking we're a pager, because it already knows we're not a tty val colorSupport: Seq[(String, String)] = - if(ConsoleLogger.formatEnabled) Seq("GIT_PAGER_IN_USE" -> "1") + if(ConsoleAppender.formatEnabledInEnv) Seq("GIT_PAGER_IN_USE" -> "1") else Seq.empty override def apply(args: String*)(cwd: File, log: Logger = ConsoleLogger()): String = { val gitLogger = new GitLogger(log) IO.createDirectory(cwd) val full = cmd ++ args - log.debug(cwd + "$ " + full.mkString(" ")) - val code = Process(full, cwd, colorSupport :_*) ! gitLogger + log.debug(s"cwd$$ ${full.mkString(" ")}") + val code = Process(full, cwd, colorSupport*) ! gitLogger val result = gitLogger.flush(code) if(code != 0) throw new MessageOnlyException("Nonzero exit code (" + code + ") running git.") diff --git a/src/main/scala/com/github/sbt/git/GitPlugin.scala b/src/main/scala/com/github/sbt/git/GitPlugin.scala index 1d99387..1764c30 100644 --- a/src/main/scala/com/github/sbt/git/GitPlugin.scala +++ b/src/main/scala/com/github/sbt/git/GitPlugin.scala @@ -170,7 +170,7 @@ object SbtGit { def useJGit: Setting[_] = ThisBuild / gitRunner := JGitRunner /** Setting to use console git for readable ops, to allow working with git worktrees */ - def useReadableConsoleGit: Setting[_] = useConsoleForROGit in ThisBuild := true + def useReadableConsoleGit: Setting[_] = ThisBuild / useConsoleForROGit := true /** Adapts the project prompt to show the current project name *and* the current git branch. */ def showCurrentGitBranch: Setting[_] = diff --git a/src/main/scala/com/github/sbt/git/JGit.scala b/src/main/scala/com/github/sbt/git/JGit.scala index c580884..97e4d7f 100644 --- a/src/main/scala/com/github/sbt/git/JGit.scala +++ b/src/main/scala/com/github/sbt/git/JGit.scala @@ -2,14 +2,14 @@ package com.github.sbt.git import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.storage.file.FileRepositoryBuilder -import org.eclipse.jgit.api.{Git => PGit} +import org.eclipse.jgit.api.Git as PGit import java.io.File import java.text.SimpleDateFormat import java.util.Date import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.lib.Ref -import org.eclipse.jgit.revwalk.{RevCommit, RevWalk} +import org.eclipse.jgit.revwalk.RevWalk import scala.util.Try @@ -29,13 +29,13 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { def branch: String = repo.getBranch private def branchesRef: Seq[Ref] = { - import collection.JavaConverters._ - porcelain.branchList.call.asScala + import collection.JavaConverters.* + porcelain.branchList.call.asScala.toSeq } def tags: Seq[Ref] = { - import collection.JavaConverters._ - porcelain.tagList.call().asScala + import collection.JavaConverters.* + porcelain.tagList.call().asScala.toSeq } def checkoutBranch(branch: String): Unit = { @@ -96,9 +96,9 @@ final class JGit(val repo: Repository) extends GitReadonlyInterface { override def branches: Seq[String] = branchesRef.filter(_.getName.startsWith("refs/heads")).map(_.getName.drop(11)) override def remoteBranches: Seq[String] = { - import collection.JavaConverters._ + import collection.JavaConverters.* import org.eclipse.jgit.api.ListBranchCommand.ListMode - porcelain.branchList.setListMode(ListMode.REMOTE).call.asScala.filter(_.getName.startsWith("refs/remotes")).map(_.getName.drop(13)) + porcelain.branchList.setListMode(ListMode.REMOTE).call.asScala.filter(_.getName.startsWith("refs/remotes")).map(_.getName.drop(13)).toSeq } override def remoteOrigin: String = { @@ -131,9 +131,9 @@ object JGit { /** Creates a new git instance from a base directory. */ def apply(base: File) = - try (new JGit({ + try new JGit({ new FileRepositoryBuilder().findGitDir(base).build - })) catch { + }) catch { // This is thrown if we never find the git base directory. In that instance, we'll assume root is the base dir. case e: IllegalArgumentException => val defaultGitDir = new File(base, ".git") diff --git a/src/sbt-test/git-versioning/find-tag-newest/test b/src/sbt-test/git-versioning/find-tag-newest/test index 7ab4c57..0d819e9 100644 --- a/src/sbt-test/git-versioning/find-tag-newest/test +++ b/src/sbt-test/git-versioning/find-tag-newest/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" > git tag v1.0.0 diff --git a/src/sbt-test/git-versioning/find-tag/test b/src/sbt-test/git-versioning/find-tag/test index af8892c..ec1544a 100644 --- a/src/sbt-test/git-versioning/find-tag/test +++ b/src/sbt-test/git-versioning/find-tag/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" > git tag v1.0.0 diff --git a/src/sbt-test/git-versioning/get-message/test b/src/sbt-test/git-versioning/get-message/test index 4c7a68e..c9f4ffe 100644 --- a/src/sbt-test/git-versioning/get-message/test +++ b/src/sbt-test/git-versioning/get-message/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md $ copy-file changes/build.sbt build.sbt > reload diff --git a/src/sbt-test/git-versioning/multi-module-project-use-describe/test b/src/sbt-test/git-versioning/multi-module-project-use-describe/test index 233b38d..6569305 100644 --- a/src/sbt-test/git-versioning/multi-module-project-use-describe/test +++ b/src/sbt-test/git-versioning/multi-module-project-use-describe/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" > git tag -am "a version" a-1.0 diff --git a/src/sbt-test/git-versioning/multi-module-project/test b/src/sbt-test/git-versioning/multi-module-project/test index 41a6a3c..920d28e 100644 --- a/src/sbt-test/git-versioning/multi-module-project/test +++ b/src/sbt-test/git-versioning/multi-module-project/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" $ copy-file changes/build.sbt build.sbt diff --git a/src/sbt-test/git-versioning/no-base-version/test b/src/sbt-test/git-versioning/no-base-version/test index 41a6a3c..920d28e 100644 --- a/src/sbt-test/git-versioning/no-base-version/test +++ b/src/sbt-test/git-versioning/no-base-version/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" $ copy-file changes/build.sbt build.sbt diff --git a/src/sbt-test/git-versioning/uncommitted-signifier/test b/src/sbt-test/git-versioning/uncommitted-signifier/test index 7101eaa..527ad34 100644 --- a/src/sbt-test/git-versioning/uncommitted-signifier/test +++ b/src/sbt-test/git-versioning/uncommitted-signifier/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" $ copy-file changes/build.sbt build.sbt diff --git a/src/sbt-test/git-versioning/use-describe-with-matching/test b/src/sbt-test/git-versioning/use-describe-with-matching/test index bfc6e2b..0225335 100644 --- a/src/sbt-test/git-versioning/use-describe-with-matching/test +++ b/src/sbt-test/git-versioning/use-describe-with-matching/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" > git tag module-1.0.0 diff --git a/src/sbt-test/git-versioning/use-describe/test b/src/sbt-test/git-versioning/use-describe/test index 42d1281..531976e 100644 --- a/src/sbt-test/git-versioning/use-describe/test +++ b/src/sbt-test/git-versioning/use-describe/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" > git tag v1.0.0 diff --git a/src/sbt-test/git-versioning/with-base-version/test b/src/sbt-test/git-versioning/with-base-version/test index 41a6a3c..920d28e 100644 --- a/src/sbt-test/git-versioning/with-base-version/test +++ b/src/sbt-test/git-versioning/with-base-version/test @@ -1,6 +1,8 @@ > git init > git config user.email "test@jsuereth.com" > git config user.name "Tester" +> git config core.hookspath /dev/null +> git config commit.gpgsign false > git add README.md > git commit -m "test" $ copy-file changes/build.sbt build.sbt From 26a5652bda0f0ae3c5c83497ed7272042f6f1d8d Mon Sep 17 00:00:00 2001 From: Adriaan Groenenboom Date: Mon, 7 Oct 2024 19:46:32 +0200 Subject: [PATCH 2/2] Cross build sbt 1.x and 2.x --- .github/workflows/ci.yml | 2 +- build.sbt | 70 ++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0da59c7..4ed1478 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: Build and test run: | gpg --import test-key.gpg - sbt -v clean ^test ^scripted + sbt -v clean +test +scripted rm -rf "$HOME/.ivy2/local" || true find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true diff --git a/build.sbt b/build.sbt index 5f499d6..7470293 100644 --- a/build.sbt +++ b/build.sbt @@ -1,24 +1,46 @@ -organization := "com.github.sbt" -//sonatypeProfileName := "com.github.sbt" -name := "sbt-git" -licenses := Seq(("BSD-2-Clause", url("https://opensource.org/licenses/BSD-2-Clause"))) -description := "An sbt plugin that offers git features directly inside sbt" -developers := List(Developer("jsuereth", "Josh Suereth", "joshua suereth gmail com", url("http://jsuereth.com/"))) -startYear := Some(2011) -homepage := scmInfo.value map (_.browseUrl) -scmInfo := Some(ScmInfo(url("https://github.com/sbt/sbt-git"), "scm:git:git@github.com:sbt/sbt-git.git")) - -//crossSbtVersions := List("1.3.13") - -enablePlugins(SbtPlugin) -//TODO: enablePlugins(GitVersioning, SbtPlugin) -//git.baseVersion := "1.0" - -libraryDependencies ++= Seq( - "org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.3.202401111512-r", - "com.michaelpollmeier" % "versionsort" % "1.0.11", - "org.scalameta" %% "munit" % "1.0.2" % Test -) - -scriptedLaunchOpts += s"-Dproject.version=${version.value}" -scriptedBufferLog := false \ No newline at end of file +val sbtGit = project + .in(file(".")) + .enablePlugins(SbtPlugin) + //TODO: enablePlugins(GitVersioning, SbtPlugin) + .settings( + organization := "com.github.sbt", + //sonatypeProfileName := "com.github.sbt", + name := "sbt-git", + licenses := Seq( + ("BSD-2-Clause", url("https://opensource.org/licenses/BSD-2-Clause")) + ), + description := "An sbt plugin that offers git features directly inside sbt", + developers := List( + Developer( + "jsuereth", + "Josh Suereth", + "joshua suereth gmail com", + url("http://jsuereth.com/") + ) + ), + startYear := Some(2011), + homepage := scmInfo.value map (_.browseUrl), + scmInfo := Some( + ScmInfo( + url("https://github.com/sbt/sbt-git"), + "scm:git:git@github.com:sbt/sbt-git.git" + ) + ), +//crossSbtVersions := List("1.3.13"), +//git.baseVersion := "1.0", + libraryDependencies ++= Seq( + "org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.3.202401111512-r", + "com.michaelpollmeier" % "versionsort" % "1.0.11", + "org.scalameta" %% "munit" % "1.0.2" % Test + ), + // [error] (Compile / doc) java.lang.ClassNotFoundException: dotty.tools.dottydoc.Main + packageDoc / publishArtifact := false, + crossScalaVersions := Seq("2.12.20", "3.3.4"), + (pluginCrossBuild / sbtVersion) := { + scalaBinaryVersion.value match { + case "2.12" => "1.3.0" + case _ => "2.0.0-M2" + } + }, + scriptedLaunchOpts += s"-Dproject.version=${version.value}" + )