Skip to content

Commit

Permalink
Improve compatability with configuration caching (#854)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
(cherry picked from commit ae69e86)
  • Loading branch information
SUPERCILEX committed Jun 27, 2021
1 parent 8ed9260 commit 055e41b
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import com.github.triplet.gradle.play.tasks.internal.workers.copy
import com.github.triplet.gradle.play.tasks.internal.workers.paramsForBase
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkAction
import org.gradle.workers.WorkParameters
import org.gradle.workers.WorkerExecutor
Expand All @@ -34,6 +34,8 @@ import javax.inject.Inject
internal abstract class Bootstrap @Inject constructor(
extension: PlayPublisherExtension,
optionsHolder: BootstrapOptions.Holder,
private val fileOps: FileSystemOperations,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension), BootstrapOptions by optionsHolder {
@get:OutputDirectory
abstract val srcDir: DirectoryProperty
Expand All @@ -45,9 +47,8 @@ internal abstract class Bootstrap @Inject constructor(

@TaskAction
fun bootstrap() {
project.delete(srcDir)
fileOps.delete { delete(srcDir) }

val executor = project.serviceOf<WorkerExecutor>()
if (downloadAppDetails) bootstrapAppDetails(executor)
if (downloadListings) bootstrapListings(executor)
if (downloadReleaseNotes) bootstrapReleaseNotes(executor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import com.github.triplet.gradle.play.tasks.internal.workers.paramsForBase
import org.gradle.api.logging.Logging
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import javax.inject.Inject

internal abstract class CommitEdit @Inject constructor(
extension: PlayPublisherExtension,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension) {
@TaskAction
fun commit() {
Expand All @@ -22,7 +22,7 @@ internal abstract class CommitEdit @Inject constructor(
return
}

project.serviceOf<WorkerExecutor>().noIsolation().submit(Committer::class) {
executor.noIsolation().submit(Committer::class) {
paramsForBase(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.FileType
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputFiles
Expand All @@ -32,7 +33,6 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.work.ChangeType
import org.gradle.work.InputChanges
import org.gradle.workers.WorkAction
Expand All @@ -44,7 +44,10 @@ import java.util.TreeSet
import javax.inject.Inject

@CacheableTask
internal abstract class GenerateResources : DefaultTask() {
internal abstract class GenerateResources @Inject constructor(
private val layout: ProjectLayout,
private val executor: WorkerExecutor,
) : DefaultTask() {
@get:Internal
abstract val resSrcDirs: ListProperty<Directory>

Expand All @@ -66,16 +69,15 @@ internal abstract class GenerateResources : DefaultTask() {
.filter { it.fileType == FileType.FILE }
.map { it.changeType to it.file }

val work = project.serviceOf<WorkerExecutor>().noIsolation()
if (validateChanges.isNotEmpty()) {
work.submit(Validator::class) {
executor.noIsolation().submit(Validator::class) {
files.set(validateChanges)
inputDirs.set(resSrcDirs)
}
}
if (generateChanges.isNotEmpty()) {
work.submit(Generator::class) {
projectDirectory.set(project.layout.projectDirectory)
executor.noIsolation().submit(Generator::class) {
projectDirectory.set(layout.projectDirectory)
inputDirs.set(resSrcDirs)
outputDir.set(resDir)
changedFiles.set(generateChanges)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkAction
import org.gradle.workers.WorkParameters
import org.gradle.workers.WorkerExecutor
Expand All @@ -26,6 +25,7 @@ import javax.inject.Inject

internal abstract class InstallInternalSharingArtifact @Inject constructor(
private val extension: AppExtension,
private val executor: WorkerExecutor,
) : DefaultTask() {
@get:PathSensitive(PathSensitivity.RELATIVE)
@get:InputDirectory
Expand All @@ -39,7 +39,7 @@ internal abstract class InstallInternalSharingArtifact @Inject constructor(
@TaskAction
fun install() {
val uploads = uploadedArtifacts
project.serviceOf<WorkerExecutor>().noIsolation().submit(Installer::class) {
executor.noIsolation().submit(Installer::class) {
uploadedArtifacts.set(uploads)
adbExecutable.set(extension.adbExecutable)
timeOutInMs.set(extension.adbOptions.timeOutInMs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import javax.inject.Inject
import kotlin.math.max

internal abstract class ProcessArtifactVersionCodes @Inject constructor(
extension: PlayPublisherExtension,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension) {
@get:Input
internal abstract val versionCodes: ListProperty<Int>
Expand All @@ -32,7 +32,7 @@ internal abstract class ProcessArtifactVersionCodes @Inject constructor(

@TaskAction
fun process() {
project.serviceOf<WorkerExecutor>().noIsolation().submit(VersionCoder::class) {
executor.noIsolation().submit(VersionCoder::class) {
paramsForBase(this)
defaultVersionCodes.set(versionCodes)
nextAvailableVersionCodes.set(playVersionCodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import com.github.triplet.gradle.play.tasks.internal.workers.paramsForBase
import org.gradle.api.file.Directory
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import javax.inject.Inject

internal abstract class PromoteRelease @Inject constructor(
extension: PlayPublisherExtension,
executionDir: Directory,
private val executor: WorkerExecutor,
) : PublishArtifactTaskBase(extension),
UpdatableTrackExtensionOptions by CliOptionsImpl(extension, executionDir) {
init {
Expand All @@ -25,7 +25,7 @@ internal abstract class PromoteRelease @Inject constructor(

@TaskAction
fun promote() {
project.serviceOf<WorkerExecutor>().noIsolation().submit(Promoter::class) {
executor.noIsolation().submit(Promoter::class) {
paramsForBase(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.github.triplet.gradle.play.tasks.internal.workers.paramsForBase
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.InputFile
Expand All @@ -22,14 +23,15 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import java.io.File
import javax.inject.Inject

internal abstract class PublishApk @Inject constructor(
extension: PlayPublisherExtension,
executionDir: Directory,
private val fileOps: FileSystemOperations,
private val executor: WorkerExecutor,
) : PublishArtifactTaskBase(extension),
PublishableTrackExtensionOptions by CliOptionsImpl(extension, executionDir) {
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -55,8 +57,8 @@ internal abstract class PublishApk @Inject constructor(

@TaskAction
fun publishApks() {
project.delete(temporaryDir) // Make sure previous executions get cleared out
project.serviceOf<WorkerExecutor>().noIsolation().submit(Processor::class) {
fileOps.delete { delete(temporaryDir) } // Make sure previous executions get cleared out
executor.noIsolation().submit(Processor::class) {
paramsForBase(this)

apkFiles.set(apks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.github.triplet.gradle.play.tasks.internal.workers.paramsForBase
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.InputFiles
Expand All @@ -21,14 +22,15 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import java.io.File
import javax.inject.Inject

internal abstract class PublishBundle @Inject constructor(
extension: PlayPublisherExtension,
executionDir: Directory,
private val fileOps: FileSystemOperations,
private val executor: WorkerExecutor,
) : PublishArtifactTaskBase(extension),
PublishableTrackExtensionOptions by CliOptionsImpl(extension, executionDir) {
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -44,8 +46,8 @@ internal abstract class PublishBundle @Inject constructor(

@TaskAction
fun publishBundles() {
project.delete(temporaryDir) // Make sure previous executions get cleared out
project.serviceOf<WorkerExecutor>().noIsolation().submit(Processor::class) {
fileOps.delete { delete(temporaryDir) } // Make sure previous executions get cleared out
executor.noIsolation().submit(Processor::class) {
paramsForBase(this)

bundleFiles.set(bundles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import java.io.File
import javax.inject.Inject

internal abstract class PublishInternalSharingApk @Inject constructor(
extension: PlayPublisherExtension,
executionDir: Directory,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension),
ArtifactExtensionOptions by CliOptionsImpl(extension, executionDir) {
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -39,7 +39,7 @@ internal abstract class PublishInternalSharingApk @Inject constructor(

@TaskAction
fun publishApk() {
project.serviceOf<WorkerExecutor>().noIsolation().submit(Processor::class) {
executor.noIsolation().submit(Processor::class) {
paramsForBase(this)

apkFiles.set(apks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.workers.WorkerExecutor
import java.io.File
import javax.inject.Inject

internal abstract class PublishInternalSharingBundle @Inject constructor(
extension: PlayPublisherExtension,
executionDir: Directory,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension),
ArtifactExtensionOptions by CliOptionsImpl(extension, executionDir) {
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -39,7 +39,7 @@ internal abstract class PublishInternalSharingBundle @Inject constructor(

@TaskAction
fun publishBundle() {
project.serviceOf<WorkerExecutor>().noIsolation().submit(Processor::class) {
executor.noIsolation().submit(Processor::class) {
paramsForBase(this)

bundleFiles.set(bundles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.work.Incremental
import org.gradle.work.InputChanges
import org.gradle.workers.WorkerExecutor
Expand All @@ -42,6 +41,7 @@ import javax.inject.Inject
internal abstract class PublishListings @Inject constructor(
extension: PlayPublisherExtension,
executionDir: Directory,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension),
WriteTrackExtensionOptions by CliOptionsImpl(extension, executionDir) {
@get:Internal
Expand Down Expand Up @@ -99,7 +99,7 @@ internal abstract class PublishListings @Inject constructor(

if (details == null && listings.isEmpty() && media.isEmpty()) return

project.serviceOf<WorkerExecutor>().noIsolation().submit(Publisher::class) {
executor.noIsolation().submit(Publisher::class) {
paramsForBase(this)

this.details.set(details)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.submit
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.work.ChangeType
import org.gradle.work.Incremental
import org.gradle.work.InputChanges
Expand All @@ -26,6 +25,7 @@ import javax.inject.Inject

internal abstract class PublishProducts @Inject constructor(
extension: PlayPublisherExtension,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension) {
@get:Incremental
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -47,7 +47,6 @@ internal abstract class PublishProducts @Inject constructor(

@TaskAction
fun publishProducts(changes: InputChanges) {
val executor = project.serviceOf<WorkerExecutor>()
changes.getFileChanges(productsDir)
.filterNot { it.changeType == ChangeType.REMOVED }
.filter { it.fileType == FileType.FILE }
Expand Down

0 comments on commit 055e41b

Please sign in to comment.