Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross build with sbt 2.0.0-M2 #255

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 46 additions & 22 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,22 +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(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}"
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}"
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.2
sbt.version=2.0.0-M2
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
14 changes: 8 additions & 6 deletions src/main/scala/com/github/sbt/git/ConsoleGitRunner.scala
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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")
Comment on lines -20 to +22
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both methods are deprecated, the latter points to Terminal.isColorEnabled, but that one's private. I'm not sure if these will be removed in the final 2.x, but for now I couldn't find a suitable replacement.

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.")
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/github/sbt/git/GitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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[_] =
Expand Down
20 changes: 10 additions & 10 deletions src/main/scala/com/github/sbt/git/JGit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/find-tag-newest/test
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +4 to +5
Copy link
Author

@agboom agboom Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some scripted tests started to take a very long time. I figured it was waiting for a GPG password prompt, so I added these lines I added before in a plugin of my own. Now they quickly pass on my machine.

> git add README.md
> git commit -m "test"
> git tag v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/find-tag/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/get-message/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/multi-module-project/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/no-base-version/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/uncommitted-signifier/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/use-describe-with-matching/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/use-describe/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/sbt-test/git-versioning/with-base-version/test
Original file line number Diff line number Diff line change
@@ -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
Expand Down