Skip to content

Commit

Permalink
Move executable searching to task action in compile task
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaracha committed Oct 14, 2024
1 parent 1cc4141 commit 94aeb42
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package de.infolektuell.gradle.typst.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.file.*
import org.gradle.api.provider.*
import org.gradle.api.tasks.*
import org.gradle.process.ExecOperations
Expand All @@ -14,7 +10,8 @@ import org.gradle.workers.WorkParameters
import org.gradle.workers.WorkerExecutor
import javax.inject.Inject

abstract class TypstCompileTask @Inject constructor(objects: ObjectFactory, private val executor: WorkerExecutor) : DefaultTask() {
@Suppress("LeakingThis")
abstract class TypstCompileTask @Inject constructor(private val executor: WorkerExecutor) : DefaultTask() {
interface SourceDirectories {
@get:InputFiles
val data: SetProperty<Directory>
Expand Down Expand Up @@ -50,26 +47,25 @@ abstract class TypstCompileTask @Inject constructor(objects: ObjectFactory, priv
}

@get:InputDirectory
val compiler: DirectoryProperty = objects.directoryProperty()
@get:Internal
val executable: Provider<String> = compiler.map { it.asFileTree.matching { spec -> spec.include("**/typst", "**/typst.exe") }.singleFile.absolutePath }
abstract val compiler: DirectoryProperty
@get:InputFiles
val documents: ListProperty<RegularFile> = objects.listProperty(RegularFile::class.java)
abstract val documents: ListProperty<RegularFile>
@get:Input
abstract val root: Property<String>
@get:Input
abstract val variables: MapProperty<String, String>
@get:Nested
abstract val sources: SourceDirectories
@get:OutputDirectory
val destinationDir: DirectoryProperty = objects.directoryProperty()
abstract val destinationDir: DirectoryProperty
@get:OutputFiles
val compiled: Provider<List<RegularFile>> = documents.zip(destinationDir) { docs, dest ->
docs.map { dest.file(it.asFile.nameWithoutExtension + ".pdf") }
}

@TaskAction
protected fun compile () {
val executable = compiler.asFileTree.matching { spec -> spec.include("**/typst", "**/typst.exe") }.singleFile.absolutePath
val queue = executor.noIsolation()
documents.get().forEach { document ->
queue.submit(TypstAction::class.java) { params ->
Expand Down

0 comments on commit 94aeb42

Please sign in to comment.