All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.objectbox.gradle.transform.ObjectBoxTestClassesTransformTask.kt Maven / Gradle / Ivy

/*
 * ObjectBox Build Tools
 * Copyright (C) 2021-2024 ObjectBox Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */

package io.objectbox.gradle.transform

import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import java.io.File


/**
 * Transforms class (byte code) files used by Android local unit tests (those that run on the dev machine).
 */
abstract class ObjectBoxTestClassesTransformTask : DefaultTask() {

    @get:Input
    abstract val debug: Property

    @get:Classpath
    abstract val compiledClasses: ConfigurableFileCollection

    @get:OutputDirectory
    abstract val outputDir: DirectoryProperty

    @TaskAction
    fun transformClasses() {
        // Clear output directory.
        val outputDir = outputDir.asFile.get()
        outputDir.deleteRecursively()
        outputDir.mkdirs()

        ObjectBoxJavaTransform(debug.get()).transform(compiledClasses, outputDir, copyNonTransformed = false)
    }

    internal class ConfigAction(
        private val debug: Property,
        private val outputDir: File,
        private val inputClasspath: FileCollection
    ) : Action {
        override fun execute(transformTask: ObjectBoxTestClassesTransformTask) {
            transformTask.group = "objectbox"
            transformTask.description = "Transforms Java bytecode for local unit tests."
            transformTask.debug.set(debug)
            transformTask.outputDir.set(outputDir)
            transformTask.compiledClasses.from(inputClasspath)
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy