Skip to content

Commit

Permalink
Merge pull request #527 from rtyley/updates-2025
Browse files Browse the repository at this point in the history
Updates: JGit, Java 11, Scala 2.13.16, etc
  • Loading branch information
rtyley authored Jan 18, 2025
2 parents 70b3ca6 + 18fccae commit 9aad72d
Show file tree
Hide file tree
Showing 21 changed files with 109 additions and 118 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: 11
cache: sbt
- uses: actions/checkout@v4
- uses: guardian/setup-scala@v1
- name: Build and Test
run: sbt -v test
- name: Test Summary
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release

on:
workflow_dispatch:

jobs:
release:
uses: guardian/gha-scala-library-release-workflow/.github/workflows/reusable-release.yml@v1
permissions: { contents: write, pull-requests: write }
with:
GITHUB_APP_ID: 930725
SONATYPE_PROFILE_NAME: 'com.madgag'
SONATYPE_CREDENTIAL_HOST: 's01.oss.sonatype.org'
secrets:
SONATYPE_TOKEN: ${{ secrets.AUTOMATED_MAVEN_RELEASE_SONATYPE_TOKEN }}
PGP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_PGP_SECRET }}
GITHUB_APP_PRIVATE_KEY: ${{ secrets.AUTOMATED_MAVEN_RELEASE_GITHUB_APP_PRIVATE_KEY }}
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java corretto-11.0.25.9.1
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ can run anywhere Java can.
Here's a rough set of instructions for building the BFG, if you don't want to use the
pre-built [downloads](http://rtyley.github.io/bfg-repo-cleaner/#download):

* Install Java JDK 8 or above
* Install Java JDK 11 or above
* Install [sbt](https://www.scala-sbt.org/1.x/docs/Setup.html)
* `git clone [email protected]:rtyley/bfg-repo-cleaner.git`
* `cd bfg-repo-cleaner`
Expand Down
2 changes: 1 addition & 1 deletion bfg-benchmark/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Dependencies._
import Dependencies.*

libraryDependencies ++= guava ++ Seq(
madgagCompress,
Expand Down
4 changes: 2 additions & 2 deletions bfg-library/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Dependencies._
import Dependencies.*

libraryDependencies ++= guava ++ Seq(
parCollections,
Expand All @@ -9,6 +9,6 @@ libraryDependencies ++= guava ++ Seq(
slf4jSimple,
lineSplitting,
scalaGitTest % Test,
"org.apache.commons" % "commons-text" % "1.9" % Test
"org.apache.commons" % "commons-text" % "1.13.0" % Test
)

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object GitUtil {
implicit val revWalk = new RevWalk(repo)
implicit val objectReader = revWalk.getObjectReader

repo.getAllRefs.values().stream().toScala(Seq).map(_.getObjectId).filter(_.open.getType == Constants.OBJ_COMMIT)
repo.getRefDatabase.getRefs().asScala.map(_.getObjectId).filter(_.open.getType == Constants.OBJ_COMMIT)
.map(_.asRevCommit).exists(_.getFooterLines(FormerCommitFooter.Key).asScala.nonEmpty)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.madgag.textmatching.{Glob, TextMatcher}
import org.eclipse.jgit.internal.storage.file.FileRepository
import org.eclipse.jgit.lib.{ObjectId, ObjectReader}

import java.nio.charset.Charset
import java.nio.charset.{Charset, StandardCharsets}
import java.nio.file.{Files, Path}
import scala.jdk.StreamConverters._
import scala.util.{Try, Using}
Expand All @@ -50,7 +50,7 @@ class LfsBlobConverter(

val gitAttributesLine = s"$lfsGlobExpression filter=lfs diff=lfs merge=lfs -text"

implicit val UTF_8 = Charset.forName("UTF-8")
implicit val UTF_8: Charset = StandardCharsets.UTF_8

val lfsPointerMemo = MemoUtil.concurrentCleanerMemo[ObjectId]()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class ObjectIdCleaner(config: ObjectIdCleaner.Config, objectDB: ObjectDatabase,
tb.setTagger(originalTag.getTaggerIdent)
tb.setMessage(objectIdSubstitutor.replaceOldIds(originalTag.getFullMessage, threadLocalResources.reader(), apply))
val cleanedTag: ObjectId = threadLocalResources.inserter().insert(tb)
objectChecker.foreach(_.checkTag(tb.toByteArray))
objectChecker.foreach(_.checkTag(tb.build()))
cleanedTag
}.getOrElse(originalTag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package com.madgag.git.bfg.cleaner

import com.madgag.git._
import com.madgag.git.bfg.Timing
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.{ObjectId, ProgressMonitor, RefDatabase}
import org.eclipse.jgit.revwalk.RevSort._
import org.eclipse.jgit.revwalk.{RevCommit, RevWalk}
import org.eclipse.jgit.transport.ReceiveCommand
Expand Down Expand Up @@ -66,14 +66,14 @@ When updating a Tree, the User has no right to muck with sub-trees. They can onl
object RepoRewriter {

def rewrite(repo: org.eclipse.jgit.lib.Repository, objectIdCleanerConfig: ObjectIdCleaner.Config): Map[ObjectId, ObjectId] = {
assert(!repo.getAllRefs.isEmpty, "Can't find any refs in repo at " + repo.getDirectory.getAbsolutePath)
implicit val refDatabase: RefDatabase = repo.getRefDatabase

implicit val refDatabase = repo.getRefDatabase
assert(refDatabase.hasRefs, "Can't find any refs in repo at " + repo.getDirectory.getAbsolutePath)

val reporter: Reporter = new CLIReporter(repo)
implicit val progressMonitor = reporter.progressMonitor
implicit val progressMonitor: ProgressMonitor = reporter.progressMonitor

val allRefs = repo.getAllRefs.values
val allRefs = refDatabase.getRefs().asScala

def createRevWalk: RevWalk = {

Expand All @@ -82,7 +82,7 @@ object RepoRewriter {
revWalk.sort(TOPO) // crucial to ensure we visit parents BEFORE children, otherwise blow stack
revWalk.sort(REVERSE, true) // we want to start with the earliest commits and work our way up...

val startCommits = allRefs.asScala.map(_.targetObjectId.asRevObject(revWalk)).collect { case c: RevCommit => c }
val startCommits = allRefs.map(_.targetObjectId.asRevObject(revWalk)).collect { case c: RevCommit => c }

revWalk.markStart(startCommits.asJavaCollection)
revWalk
Expand All @@ -91,7 +91,7 @@ object RepoRewriter {
implicit val revWalk = createRevWalk
implicit val reader = revWalk.getObjectReader

reporter.reportRefsForScan(allRefs.asScala)
reporter.reportRefsForScan(allRefs)

reporter.reportObjectProtection(objectIdCleanerConfig)(repo.getObjectDatabase, revWalk)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.eclipse.jgit.lib.Constants.OBJ_COMMIT
import org.eclipse.jgit.lib._
import org.eclipse.jgit.revwalk.RevCommit

import java.nio.charset.StandardCharsets.UTF_8
import java.nio.charset.{Charset, IllegalCharsetNameException, UnsupportedCharsetException}
import scala.jdk.CollectionConverters._

Expand Down Expand Up @@ -59,10 +60,10 @@ case class CommitArcs(parents: Seq[ObjectId], tree: ObjectId) {

object CommitNode {
def apply(c: RevCommit): CommitNode = CommitNode(c.getAuthorIdent, c.getCommitterIdent, c.getFullMessage,
try c.getEncoding catch {case e @ (_ : IllegalCharsetNameException | _ : UnsupportedCharsetException) => Constants.CHARSET})
try c.getEncoding catch {case e @ (_ : IllegalCharsetNameException | _ : UnsupportedCharsetException) => UTF_8})
}

case class CommitNode(author: PersonIdent, committer: PersonIdent, message: String, encoding: Charset = Constants.CHARSET) {
case class CommitNode(author: PersonIdent, committer: PersonIdent, message: String, encoding: Charset = UTF_8) {
lazy val subject = message.linesIterator.to(LazyList).headOption
lazy val lastParagraphBreak = message.lastIndexOf("\n\n")
lazy val messageWithoutFooters = if (footers.isEmpty) message else (message take lastParagraphBreak)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ package com.madgag.git.bfg

import com.madgag.git._
import com.madgag.git.test._
import org.eclipse.jgit.internal.storage.file.FileRepository
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class GitUtilSpec extends AnyFlatSpec with Matchers {
implicit val repo = unpackRepo("/sample-repos/example.git.zip")
implicit val repo: FileRepository = unpackRepo("/sample-repos/example.git.zip")

"reachable blobs" should "match expectations" in {
implicit val (revWalk, reader) = repo.singleThreadedReaderTuple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package com.madgag.git.bfg.test

import com.madgag.git._
import com.madgag.git.test._
import org.eclipse.jgit.internal.storage.file.{GC, ObjectDirectory}
import org.eclipse.jgit.internal.storage.file.{FileRepository, GC, ObjectDirectory}
import org.eclipse.jgit.lib.Constants.OBJ_BLOB
import org.eclipse.jgit.lib.{ObjectId, ObjectReader, Repository}
import org.eclipse.jgit.revwalk.{RevCommit, RevTree}
import org.eclipse.jgit.revwalk.{RevCommit, RevTree, RevWalk}
import org.eclipse.jgit.treewalk.TreeWalk
import org.scalatest.Inspectors
import org.scalatest.flatspec.AnyFlatSpec
Expand All @@ -16,9 +16,9 @@ import scala.jdk.CollectionConverters._

class unpackedRepo(filePath: String) extends AnyFlatSpec with Matchers {

implicit val repo = unpackRepo(filePath)
implicit val objectDirectory = repo.getObjectDatabase.asInstanceOf[ObjectDirectory]
implicit lazy val (revWalk, reader) = repo.singleThreadedReaderTuple
implicit val repo: FileRepository = unpackRepo(filePath)
implicit val objectDirectory: ObjectDirectory = repo.getObjectDatabase
implicit lazy val (revWalk: RevWalk, reader: ObjectReader) = repo.singleThreadedReaderTuple


def blobOfSize(sizeInBytes: Int): Matcher[ObjectId] = Matcher { (objectId: ObjectId) =>
Expand All @@ -29,8 +29,8 @@ class unpackedRepo(filePath: String) extends AnyFlatSpec with Matchers {
}

def packedBlobsOfSize(sizeInBytes: Long): Set[ObjectId] = {
implicit val reader = repo.newObjectReader()
repo.getObjectDatabase.asInstanceOf[ObjectDirectory].packedObjects.filter { objectId =>
implicit val reader: ObjectReader = repo.newObjectReader()
repo.getObjectDatabase.packedObjects.filter { objectId =>
val objectLoader = objectId.open
objectLoader.getType == OBJ_BLOB && objectLoader.getSize == sizeInBytes
}.toSet
Expand Down
19 changes: 13 additions & 6 deletions bfg/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.io.{File, FileOutputStream}

import Dependencies._
import Dependencies.*
import sbt.taskKey

import scala.sys.process.Process
Expand All @@ -13,30 +13,37 @@ gitDescription := Try[String](Process("git describe --all --always --dirty --lon
libraryDependencies += useNewerJava

mainClass := Some("use.newer.java.Version8")
packageOptions in (Compile, packageBin) +=
Compile / packageBin / packageOptions +=
Package.ManifestAttributes( "Main-Class-After-UseNewerJava-Check" -> "com.madgag.git.bfg.cli.Main" )

// note you don't want the jar name to collide with the non-assembly jar, otherwise confusion abounds.
assembly / assemblyJarName := s"${name.value}-${version.value}-${gitDescription.value}${jgitVersionOverride.map("-jgit-" + _).mkString}.jar"

assembly / assemblyMergeStrategy := {
case PathList("META-INF", "versions", "9", "module-info.class") => MergeStrategy.discard
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
}

buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion, gitDescription)

buildInfoPackage := "com.madgag.git.bfg"

crossPaths := false

publishArtifact in (Compile, packageBin) := false
Compile / packageBin / publishArtifact := false

// replace the conventional main artifact with an uber-jar
addArtifact(artifact in (Compile, packageBin), assembly)
addArtifact(Compile / packageBin / artifact, assembly)

val cliUsageDump = taskKey[File]("Dump the CLI 'usage' output to a file")

cliUsageDump := {
val usageDumpFile = File.createTempFile("bfg-usage", "dump.txt")
val scalaRun = new ForkRun(ForkOptions().withOutputStrategy(CustomOutput(new FileOutputStream(usageDumpFile))))

val mainClassName = (mainClass in (Compile, run)).value getOrElse sys.error("No main class detected.")
val mainClassName = (Compile / run / mainClass).value getOrElse sys.error("No main class detected.")
val classpath = Attributed.data((Runtime / fullClasspath).value)
val args = Seq.empty

Expand All @@ -52,7 +59,7 @@ libraryDependencies ++= Seq(
scalaGitTest % "test"
)

import Tests._
import Tests.*
{
def isolateTestsWhichRequireTheirOwnJvm(tests: Seq[TestDefinition]) = {
val (testsRequiringIsolation, testsNotNeedingIsolation) = tests.partition(_.name.contains("RequiresOwnJvm"))
Expand Down
4 changes: 2 additions & 2 deletions bfg/src/main/scala/com/madgag/git/bfg/cli/CLIConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object CLIConfig {
val parser = new OptionParser[CLIConfig]("bfg") {

def fileMatcher(name: String, defaultType: TextMatcherType = Glob) = {
implicit val textMatcherRead = Read.reads { TextMatcher(_, defaultType) }
implicit val textMatcherRead: Read[TextMatcher] = Read.reads { TextMatcher(_, defaultType) }

opt[TextMatcher](name).valueName(s"<${defaultType.expressionPrefix}>").validate { m =>
if (m.expression.contains('/')) {
Expand Down Expand Up @@ -143,7 +143,7 @@ case class CLIConfig(stripBiggestBlobs: Option[Int] = None,

lazy val gitdir = resolveGitDirFor(repoLocation)

implicit lazy val repo = FileRepositoryBuilder.create(gitdir.get).asInstanceOf[FileRepository]
implicit lazy val repo: FileRepository = FileRepositoryBuilder.create(gitdir.get).asInstanceOf[FileRepository]

lazy val objectProtection = ProtectedObjectCensus(protectBlobsFromRevisions)

Expand Down
6 changes: 3 additions & 3 deletions bfg/src/test/scala/com/madgag/git/bfg/cli/MainSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.madgag.git.bfg.cli
import com.madgag.git._
import com.madgag.git.bfg.cli.test.unpackedRepo
import com.madgag.git.bfg.model._
import org.eclipse.jgit.lib.ObjectId
import org.eclipse.jgit.lib.{ObjectId, ObjectReader}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{Inspectors, OptionValues}
Expand All @@ -36,7 +36,7 @@ class MainSpec extends AnyFlatSpec with Matchers with OptionValues with Inspecto
// concurrent testing against scala.App is not safe https://twitter.com/rtyley/status/340376844916387840

"CLI" should "not change commits unnecessarily" in new unpackedRepo("/sample-repos/exampleWithInitialCleanHistory.git.zip") {
implicit val r = reader
implicit val r: ObjectReader = reader

ensureInvariantValue(commitHist() take 2) {
ensureRemovalFrom(commitHist()).ofCommitsThat(haveCommitWhereObjectIds(contain(abbrId("294f")))) {
Expand Down Expand Up @@ -90,7 +90,7 @@ class MainSpec extends AnyFlatSpec with Matchers with OptionValues with Inspecto
}

"strip blobs by id" should "work" in new unpackedRepo("/sample-repos/example.git.zip") {
implicit val r = reader
implicit val r: ObjectReader = reader

val badBlobs = Set(abbrId("db59"), abbrId("86f9"))
val blobIdsFile = Files.createTempFile("test-strip-blobs",".ids")
Expand Down
56 changes: 25 additions & 31 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
import Dependencies._
import common._
import ReleaseTransformations.*
import Dependencies.*

ThisBuild / organization := "com.madgag"

ThisBuild / scalaVersion := "2.13.10"
ThisBuild / scalaVersion := "2.13.16"

ThisBuild / scalacOptions ++= Seq("-deprecation", "-feature", "-language:postfixOps")
ThisBuild / scalacOptions ++= Seq("-deprecation", "-feature", "-language:postfixOps", "-release:11")

ThisBuild / licenses := Seq("GPLv3" -> url("http://www.gnu.org/licenses/gpl-3.0.html"))

ThisBuild / homepage := Some(url("https://github.com/rtyley/bfg-repo-cleaner"))
ThisBuild / licenses := Seq(License.GPL3_or_later)

ThisBuild / resolvers ++= jgitVersionOverride.map(_ => Resolver.mavenLocal).toSeq

ThisBuild / libraryDependencies += scalatest % Test

ThisBuild / Test/testOptions += Tests.Argument(
ThisBuild / Test/ testOptions += Tests.Argument(
TestFrameworks.ScalaTest,
"-u", s"test-results/scala-${scalaVersion.value}"
)

lazy val root = Project(id = "bfg-parent", base = file(".")) aggregate (bfg, bfgTest, bfgLibrary)

releaseSignedArtifactsSettings

lazy val bfgTest = bfgProject("bfg-test")

lazy val bfgLibrary = bfgProject("bfg-library") dependsOn(bfgTest % Test)
lazy val root = Project(id = "bfg-parent", base = file(".")).aggregate (bfg, `bfg-test`, `bfg-library`).settings(
publish / skip := true,
releaseCrossBuild := true, // true if you cross-build the project for multiple Scala versions
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
setNextVersion,
commitNextVersion
)
)

lazy val bfg = bfgProject("bfg") enablePlugins(BuildInfoPlugin) dependsOn(bfgLibrary, bfgTest % Test)
lazy val `bfg-test` = project

lazy val bfgBenchmark = bfgProject("bfg-benchmark")
lazy val `bfg-library` = project.dependsOn(`bfg-test` % Test)

ThisBuild / publishTo := sonatypePublishToBundle.value
lazy val bfg = project.enablePlugins(BuildInfoPlugin).dependsOn(`bfg-library`, `bfg-test` % Test)

ThisBuild / pomExtra := (
<scm>
<url>git@github.com:rtyley/bfg-repo-cleaner.git</url>
<connection>scm:git:git@github.com:rtyley/bfg-repo-cleaner.git</connection>
</scm>
<developers>
<developer>
<id>rtyley</id>
<name>Roberto Tyley</name>
<url>https://github.com/rtyley</url>
</developer>
</developers>
)
lazy val `bfg-benchmark` = project
Loading

0 comments on commit 9aad72d

Please sign in to comment.