Skip to content

Commit

Permalink
Move from grgit to jgit
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jun 16, 2024
1 parent 962f057 commit 0b126f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import net.fabricmc.loom.build.nesting.JarNester
import net.fabricmc.loom.util.Constants
import net.fabricmc.loom.util.GroovyXmlUtil
import org.apache.commons.codec.digest.DigestUtils
import org.eclipse.jgit.api.Git
import java.util.*

plugins {
java
`maven-publish`
id("org.ajoberstar.grgit") version "4.1.1"
id("dev.architectury.loom") // Version declared in buildSrc
}

Expand Down Expand Up @@ -213,22 +213,23 @@ publishing {
}
}

val git: Git? = runCatching { Git.open(rootDir) }.getOrNull()

fun getSubprojectVersion(project: Project): String {
// Get the version from the gradle.properties file
val version = properties["${project.name}-version"] as? String
?: throw NullPointerException("Could not find version for " + project.name)

@Suppress("SENSELESS_COMPARISON")
if (rootProject.grgit == null) {
if (git == null) {
return "$version+nogit"
}

val latestCommits = rootProject.grgit.log(mapOf("paths" to listOf(project.name), "maxCommits" to 1))
val latestCommits = git.log().addPath(project.name).setMaxCount(1).call().toList()
if (latestCommits.isEmpty()) {
return "$version+uncommited"
}

return version + "+" + latestCommits[0].id.substring(0, 8) + DigestUtils.sha256Hex(versionMc).substring(0, 2)
return version + "+" + latestCommits[0].id.name.substring(0, 8) + DigestUtils.sha256Hex(versionMc).substring(0, 2)
}

fun moduleDependencies(project: Project, depNames: List<String>) {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ dependencies {
implementation("dev.architectury:at:1.0.1")

implementation("commons-codec:commons-codec:1.17.0")

implementation("org.eclipse.jgit:org.eclipse.jgit:6.9.0.202403050737-r")
}

0 comments on commit 0b126f7

Please sign in to comment.