[flutter_plugin_tools] Introduce a class for packages (#4252)

Packages are the primary conceptual object in the tool, but currently they are represented simply as Directory (or occasionally a path string). This introduces an object for packages and:
- moves a number of existing utility methods into it
- sweeps the code for the obvious cases of using `Directory` to represent a package, especially in method signatures and migrates them
- notes a few places where we should migrate later, to avoid ballooning the size of the PR

There are no doubt other cases not caught in the sweep, but this gives us a foundation both for new code, and to migrate incrementally toward as we find existing code that was missed.
This commit is contained in:
stuartmorgan
2021-08-24 16:29:56 -04:00
committed by GitHub
parent 74cf0287f9
commit 41f1c806f2
27 changed files with 440 additions and 334 deletions

View File

@ -10,6 +10,7 @@ import 'common/core.dart';
import 'common/gradle.dart';
import 'common/package_looping_command.dart';
import 'common/process_runner.dart';
import 'common/repository_package.dart';
/// Lint the CocoaPod podspecs and run unit tests.
///
@ -30,22 +31,22 @@ class LintAndroidCommand extends PackageLoopingCommand {
'Requires the example to have been build at least once before running.';
@override
Future<PackageResult> runForPackage(Directory package) async {
Future<PackageResult> runForPackage(RepositoryPackage package) async {
if (!pluginSupportsPlatform(kPlatformAndroid, package,
requiredMode: PlatformSupport.inline)) {
return PackageResult.skip(
'Plugin does not have an Android implemenatation.');
}
final Directory exampleDirectory = package.childDirectory('example');
final GradleProject project = GradleProject(exampleDirectory,
final RepositoryPackage example = package.getSingleExampleDeprecated();
final GradleProject project = GradleProject(example.directory,
processRunner: processRunner, platform: platform);
if (!project.isConfigured()) {
return PackageResult.fail(<String>['Build example before linting']);
}
final String packageName = package.basename;
final String packageName = package.directory.basename;
// Only lint one build mode to avoid extra work.
// Only lint the plugin project itself, to avoid failing due to errors in