Skip to content

Commit

Permalink
Addresses comments
Browse files Browse the repository at this point in the history
  • Loading branch information
garanj committed Dec 6, 2024
1 parent b781435 commit 79b9e73
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import com.android.build.api.variant.BuiltArtifactsLoader
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.Directory
import org.gradle.api.provider.Provider
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
Expand All @@ -33,17 +34,19 @@ const val SET_WATCH_FACE_CMD =
/**
* Installs and sets watch face on an attached device via ADB.
*/
open class AdbInstallTask @Inject constructor(@Internal val execOperations: ExecOperations) :
DefaultTask() {
abstract class AdbInstallTask() : DefaultTask() {
@get:Inject
abstract val execOperations: ExecOperations

@set:Option(option = "device", description = "The ADB device to install on")
@get:Input
var device: String = ""

@get:Input
lateinit var apkLocation: Provider<Directory>
@get:InputDirectory
abstract val apkLocation: DirectoryProperty

@get:Input
lateinit var artifactLoader: BuiltArtifactsLoader
@get:Internal
abstract val artifactsLoader: Property<BuiltArtifactsLoader>

// As this task has no outputs defined, it will always be executed, which is desirable as the
// APK should be installed even if the APK itself hasn't changed. (It may have been removed from
Expand All @@ -52,7 +55,8 @@ open class AdbInstallTask @Inject constructor(@Internal val execOperations: Exec
@TaskAction
fun install() {
val artifacts =
artifactLoader.load(apkLocation.get()) ?: throw GradleException("Cannot load APKs")
artifactsLoader.get().load(apkLocation.get())
?: throw GradleException("Cannot load APKs")
if (artifacts.elements.size != 1)
throw GradleException("Expected only one APK!")
val apkPath = File(artifacts.elements.single().outputFile).toPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ import javax.inject.Inject
/**
* Runs the Memory Footprint checker tool.
*/
abstract class MemoryFootprintTask @Inject constructor(@Internal val execOperations: ExecOperations) :
DefaultTask() {
abstract class MemoryFootprintTask() : DefaultTask() {
init {
// Setting the outputs to always be up to date, meaning that this task will only run if the
// input changes (or if the last run was not successful).
this.outputs.upToDateWhen { true }
}

@get:Inject
abstract val execOperations: ExecOperations

@get:InputDirectory
abstract val apkLocation: DirectoryProperty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
Expand All @@ -36,12 +35,16 @@ import javax.inject.Inject
* Runs the validator against WFF XML files.
*/
@CacheableTask
abstract class ValidateWffFilesTask @Inject constructor(@Internal val execOperations: ExecOperations) :
DefaultTask() {
abstract class ValidateWffFilesTask : DefaultTask() {
init {
// Setting the outputs to always be up to date, meaning that this task will only run if the
// input changes (or if the last run was not successful).
this.outputs.upToDateWhen { true }
}

@get:Inject
abstract val execOperations: ExecOperations

@get:InputFiles
@get:Incremental
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,39 @@ const val DOWNLOAD_VALIDATOR_TASK = "downloadWffValidator"
const val DOWNLOAD_MEMORY_FOOTPRINT_TASK = "downloadMemoryFootprint"
const val INSTALL_TASK = "validateWffAndInstall"

private const val DEFAULT_RELEASE_TAG = "release"
private const val VALIDATOR_URL =
"https://github.com/google/watchface/releases/download/release/dwf-format-2-validator-1.0.jar"
private const val VALIDATOR_PATH = "validator/validator.jar"
"https://github.com/google/watchface/releases/download/%s/dwf-format-2-validator-1.0.jar"
private const val VALIDATOR_PATH = "validator/validator-%s.jar"
private const val MEMORY_FOOTPRINT_URL =
"https://github.com/google/watchface/releases/download/latest/memory-footprint.jar"
private const val MEMORY_FOOTPRINT_PATH = "memory-footprint/memory-footprint.jar"
"https://github.com/google/watchface/releases/download/%s/memory-footprint.jar"
private const val MEMORY_FOOTPRINT_PATH = "memory-footprint/memory-footprint-%s.jar"

class WffValidatorPlugin : Plugin<Project> {
private lateinit var manifestPath: String

override fun apply(project: Project) {
// Parameter optionally set on the command-line for the whole project, indicating which tag
// to use for releases downloaded from the watch face repo. Defaults to "release" but could
// be set to "latest".
val toolReleaseTag = project.properties["release"] ?: DEFAULT_RELEASE_TAG

val validatorUrl = VALIDATOR_URL.format(toolReleaseTag)
val memoryFootprintUrl = MEMORY_FOOTPRINT_URL.format(toolReleaseTag)
val validatorJar = VALIDATOR_PATH.format(toolReleaseTag)
val memoryFootprintJar = MEMORY_FOOTPRINT_PATH.format(toolReleaseTag)

val validatorDownloadTask =
project.tasks.register<WffToolDownloadTask>(DOWNLOAD_VALIDATOR_TASK) {
val validatorPath = project.layout.buildDirectory.file(VALIDATOR_PATH)
this.toolUrl.set(VALIDATOR_URL)
val validatorPath = project.layout.buildDirectory.file(validatorJar)
this.toolUrl.set(validatorUrl)
this.toolJarPath.set(validatorPath)
}

val memoryFootprintDownloadTask =
project.tasks.register<WffToolDownloadTask>(DOWNLOAD_MEMORY_FOOTPRINT_TASK) {
val memoryFootprintPath = project.layout.buildDirectory.file(MEMORY_FOOTPRINT_PATH)
this.toolUrl.set(MEMORY_FOOTPRINT_URL)
val memoryFootprintPath = project.layout.buildDirectory.file(memoryFootprintJar)
this.toolUrl.set(memoryFootprintUrl)
this.toolJarPath.set(memoryFootprintPath)
}

Expand Down Expand Up @@ -91,8 +102,8 @@ class WffValidatorPlugin : Plugin<Project> {

// Register additional task that allows for installing and setting of watch face.
proj.tasks.register<AdbInstallTask>(INSTALL_TASK) {
apkLocation = apkDirectoryProvider
artifactLoader = loader
apkLocation.set(apkDirectoryProvider)
artifactsLoader.set(loader)
dependsOn(ASSEMBLE_DEBUG_TASK)
}

Expand All @@ -113,5 +124,3 @@ class WffValidatorPlugin : Plugin<Project> {
.filter { it.parentFile.name.startsWith("raw") }
}
}


0 comments on commit 79b9e73

Please sign in to comment.