Skip to content

Commit

Permalink
Download service: Convert to stable API with @internal and instanciat…
Browse files Browse the repository at this point in the history
…e for each subproject
  • Loading branch information
tamaracha committed Sep 25, 2024
1 parent c32c84d commit a30fe12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import org.gradle.api.Project

abstract class GradleDownloadPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.gradle.sharedServices.registerIfAbsent(DownloadClient.SERVICE_NAME, DownloadClient::class.java)
val serviceProvider = project.gradle.sharedServices.registerIfAbsent("${project.name}_${DownloadClient.SERVICE_NAME}", DownloadClient::class.java)
project.tasks.withType(DownloadTask::class.java).configureEach { task ->
task.group = "download"
task.downloadClient.set(serviceProvider)
task.usesService(serviceProvider)
}
val extension = project.extensions.create(DownloadExtension.EXTENSION_NAME, DownloadExtension::class.java)
extension.targetDirectory.convention(project.layout.buildDirectory.dir("downloads"))
extension.resources.all { resource ->
resource.target.convention(extension.targetDirectory.file(resource.source.map { it.path.replaceBeforeLast("/", "").trim('/') }))
project.tasks.register("${resource.name}Download", DownloadTask::class.java) { task ->
task.group = "download"
task.source.set(resource.source)
task.target.set(resource.target)
task.integrity.set(resource.integrity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.services.ServiceReference
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*
import java.net.URI
import java.nio.file.Files

abstract class DownloadTask : DefaultTask() {
@get:ServiceReference(DownloadClient.SERVICE_NAME)
@get:Internal
abstract val downloadClient: Property<DownloadClient>
@get:Input
abstract val source: Property<URI>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ abstract class GradleJextractPlugin : Plugin<Project> {
val userOutput = project.layout.projectDirectory.dir(project.gradle.gradleUserHomeDir.absolutePath)
val resource: ResourceHandler = extension.generator.distribution.currentResource()
val downloadTask = project.tasks.register("downloadJextract", DownloadTask::class.java) { task ->
task.group = "download"
task.description = "Downloads Jextract for ${resource.name} platform"
task.source.set(resource.url)
task.target.set(userOutput.dir("downloads").file(resource.url.map { it.path.replaceBeforeLast("/", "").trim('/') }))
Expand Down

0 comments on commit a30fe12

Please sign in to comment.