jesswrd 58a2116d90
Convert BaseFlutterTask From Groovy to Kotlin (#163148)
Converted `BaseFlutterTask` from Groovy to Kotlin.

Note: Since it looks like Gradle prevents us from instantiating and
using an object that extends abstract class BaseFlutterTask, we must use
principles of Test Driven Development (TDD) in order to unit test
`BaseFlutterTask`. `BaseFlutterTaskHelper` was created solely for unit
testing to simulate the behavior of all functions in the original
`BaseFlutterTask`.

Fixes #162111 

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-03-14 20:36:36 +00:00

153 lines
3.3 KiB
Kotlin

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package com.flutter.gradle
import org.gradle.api.DefaultTask
import org.gradle.api.file.FileCollection
import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFiles
import java.io.File
abstract class BaseFlutterTask : DefaultTask() {
@Internal
var flutterRoot: File? = null
@Internal
var flutterExecutable: File? = null
@Input
var buildMode: String? = null
@Input
var minSdkVersion: Int? = null
@Optional
@Input
var localEngine: String? = null
@Optional
@Input
var localEngineHost: String? = null
@Optional
@Input
var localEngineSrcPath: String? = null
@Optional
@Input
var fastStart: Boolean? = null
@Input
var targetPath: String? = null
@Optional
@Input
var verbose: Boolean? = null
@Optional
@Input
var fileSystemRoots: Array<String>? = null
@Optional
@Input
var fileSystemScheme: String? = null
@Input
var trackWidgetCreation: Boolean? = null
@Optional
@Input
var targetPlatformValues: List<String>? = null
@Internal
var sourceDir: File? = null
@Internal
var intermediateDir: File? = null
@Optional
@Input
var frontendServerStarterPath: String? = null
@Optional
@Input
var extraFrontEndOptions: String? = null
@Optional
@Input
var extraGenSnapshotOptions: String? = null
@Optional
@Input
var splitDebugInfo: String? = null
@Optional
@Input
var treeShakeIcons: Boolean? = null
@Optional
@Input
var dartObfuscation: Boolean? = null
@Optional
@Input
var dartDefines: String? = null
@Optional
@Input
var bundleSkSLPath: String? = null
@Optional
@Input
var codeSizeDirectory: String? = null
@Optional
@Input
var performanceMeasurementFile: String? = null
@Optional
@Input
var deferredComponents: Boolean? = null
@Optional
@Input
var validateDeferredComponents: Boolean? = null
@Optional
@Input
var skipDependencyChecks: Boolean? = null
@Optional
@Input
var flavor: String? = null
/**
* Gets the dependency file(s) by calling [com.flutter.gradle.BaseFlutterTaskHelper.getDependenciesFiles].
*
* @return the dependency file(s) based on the current intermediate directory path.
*/
@OutputFiles
fun getDependenciesFiles(): FileCollection {
val helper = BaseFlutterTaskHelper(baseFlutterTask = this)
val depFiles = helper.getDependenciesFiles()
return depFiles
}
/**
* Builds a Flutter Android application bundle by verifying the Flutter source directory,
* creating an intermediate build directory if necessary, and running flutter assemble by
* configuring and executing with a set of build configurations.
*/
fun buildBundle() {
val helper = BaseFlutterTaskHelper(baseFlutterTask = this)
helper.checkPreConditions()
logging.captureStandardError(LogLevel.ERROR)
project.exec(helper.createExecSpecActionFromTask())
}
}