Skip to content

Commit

Permalink
packaging: Set version dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Jun 24, 2024
1 parent 2694a46 commit a9e64ab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/desktop/desktop-app-launcher/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ application {

packaging {
name.set("Bisq 2")
version.set("2.0.4")
}

javafx {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import javax.inject.Inject
class PackagingPlugin @Inject constructor(private val javaToolchainService: JavaToolchainService) : Plugin<Project> {

companion object {
const val APP_VERSION = "2.0.4"
const val OUTPUT_DIR_PATH = "packaging/jpackage/packages"
}

Expand All @@ -34,7 +33,7 @@ class PackagingPlugin @Inject constructor(private val javaToolchainService: Java

val generateHashesTask = project.tasks.register<Sha256HashTask>("generateHashes") {
inputDirFile.set(installDistTask.map { File(it.destinationDir, "lib") })
outputFile.set(getHashFileForOs(project))
outputFile.set(getHashFileForOs(project, extension))
}

val jarTask: TaskProvider<Jar> = project.tasks.named("jar", Jar::class.java)
Expand All @@ -55,7 +54,7 @@ class PackagingPlugin @Inject constructor(private val javaToolchainService: Java

licenseFile.set(File(project.projectDir.parentFile.parentFile.parentFile, "LICENSE"))
appName.set(extension.name)
appVersion.set(APP_VERSION)
appVersion.set(extension.version)

val packageResourcesDirFile = File(project.projectDir, "package")
packageResourcesDir.set(packageResourcesDirFile)
Expand All @@ -72,17 +71,19 @@ class PackagingPlugin @Inject constructor(private val javaToolchainService: Java
releaseBinariesTaskFactory.registerCopyReleaseBinariesTask()
releaseBinariesTaskFactory.registerCopyMaintainerPublicKeysTask()
releaseBinariesTaskFactory.registerCopySigningPublicKeyTask()
releaseBinariesTaskFactory.registerMergeOsSpecificJarHashesTask()
releaseBinariesTaskFactory.registerMergeOsSpecificJarHashesTask(extension.version)
}

private fun getHashFileForOs(project: Project): Provider<RegularFile> {
private fun getHashFileForOs(project: Project, extension: PackagingPluginExtension): Provider<RegularFile> {
val osName = when (getOS()) {
OS.LINUX -> "linux"
OS.MAC_OS -> "mac"
OS.WINDOWS -> "win"
}

return project.layout.buildDirectory.file("$OUTPUT_DIR_PATH/desktop-$APP_VERSION-all-$osName.jar.SHA-256")
return extension.version.flatMap { version ->
project.layout.buildDirectory.file("$OUTPUT_DIR_PATH/desktop-$version-all-$osName.jar.SHA-256")
}
}

private fun getProjectJdkDirectory(project: Project): Provider<Directory> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import org.gradle.api.provider.Property

abstract class PackagingPluginExtension {
abstract val name: Property<String>
abstract val version: Property<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bisq.gradle.packaging
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.kotlin.dsl.register
Expand Down Expand Up @@ -76,20 +77,23 @@ class ReleaseBinariesTaskFactory(private val project: Project) {
}
}

fun registerMergeOsSpecificJarHashesTask() {
fun registerMergeOsSpecificJarHashesTask(appVersion: Property<String>) {
val files = project.files(
inputBinariesProperty.map { inputDir ->
"$inputDir/desktop-${PackagingPlugin.APP_VERSION}-all-mac.jar.SHA-256"
appVersion.map { "$inputDir/desktop-$it-all-mac.jar.SHA-256" }
},
inputBinariesProperty.map { inputDir ->
"$inputDir/desktop-${PackagingPlugin.APP_VERSION}-all-linux.jar.SHA-256"
appVersion.map { "$inputDir/desktop-$it-all-linux.jar.SHA-256" }
},
inputBinariesProperty.map { inputDir ->
"$inputDir/desktop-${PackagingPlugin.APP_VERSION}-all-windows.jar.SHA-256"
appVersion.map { "$inputDir/desktop-$it-all-windows.jar.SHA-256" }
}
)
val mergedShaFile: Provider<RegularFile> = project.layout.buildDirectory
.file("packaging/release/Bisq-${PackagingPlugin.APP_VERSION}.jar.txt")

val mergedShaFile: Provider<RegularFile> = appVersion.flatMap {
project.layout.buildDirectory.file("packaging/release/Bisq-$it.jar.txt")
}

project.tasks.register<MergeOsSpecificJarHashesTask>("mergeOsSpecificJarHashes") {
hashFiles.setFrom(files)
outputFile.set(mergedShaFile)
Expand Down

0 comments on commit a9e64ab

Please sign in to comment.