From 46428e6b9158c15a5097c5daf9e8857f46940440 Mon Sep 17 00:00:00 2001 From: jesswrd Date: Wed, 18 Dec 2024 14:55:45 -0800 Subject: [PATCH 1/3] cleaned up --- script/tool/lib/src/gradle_check_command.dart | 52 ++--------- .../tool/test/gradle_check_command_test.dart | 92 +++---------------- 2 files changed, 17 insertions(+), 127 deletions(-) diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 97f818015a28..c7486a9b09ca 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -198,28 +198,10 @@ class GradleCheckCommand extends PackageLoopingCommand { return succeeded; } - /// String printed as example of valid example root settings.gradle repository - /// configuration that enables artifact hub env variable. - @visibleForTesting - static String exampleRootSettingsArtifactHubString = ''' -buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" - } - } - dependencies { - classpath "gradle.plugin.com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:2.2.1" - } -} -apply plugin: "com.google.cloud.artifactregistry.gradle-plugin" -'''; - /// String printed as a valid example of settings.gradle repository /// configuration that enables artifact hub env variable. - /// GP stands for the gradle plugin method of flutter tooling inclusion. @visibleForTesting - static String exampleSettingsArtifactHubStringGP = ''' + static String exampleSettingsArtifactHubString = ''' plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" // ...other plugins @@ -235,32 +217,15 @@ plugins { RepositoryPackage example, List gradleLines) { final RegExp documentationPresentRegex = RegExp( r'github\.com.*flutter.*blob.*Plugins-and-Packages-repository-structure.*gradle-structure'); - final RegExp artifactRegistryDefinitionRegex = RegExp( - r'classpath.*gradle\.plugin\.com\.google\.cloud\.artifactregistry:artifactregistry-gradle-plugin'); final RegExp artifactRegistryPluginApplyRegex = RegExp( - r'apply.*plugin.*com\.google\.cloud\.artifactregistry\.gradle-plugin'); - final RegExp artifactRegistryPluginApplyRegexGP = RegExp( r'id.*com\.google\.cloud\.artifactregistry\.gradle-plugin.*version.*\b\d+\.\d+\.\d+\b'); - final RegExp artifactRegistryPluginApplyDeclarativeRegex = - RegExp(r'\bpluginManagement\b'); final bool documentationPresent = gradleLines .any((String line) => documentationPresentRegex.hasMatch(line)); - final bool artifactRegistryDefined = gradleLines - .any((String line) => artifactRegistryDefinitionRegex.hasMatch(line)); - final bool artifactRegistryPluginApplied = gradleLines + final bool declarativeArtifactRegistryApplied = gradleLines .any((String line) => artifactRegistryPluginApplyRegex.hasMatch(line)); - final bool declarativeArtifactRegistryApplied = gradleLines.any( - (String line) => artifactRegistryPluginApplyRegexGP.hasMatch(line)); - final bool declarativePluginBlockApplied = gradleLines.any((String line) => - artifactRegistryPluginApplyDeclarativeRegex.hasMatch(line)); - - final bool imperativeArtifactRegistryApplied = - artifactRegistryDefined && artifactRegistryPluginApplied; - - final bool validArtifactConfiguration = documentationPresent && - (imperativeArtifactRegistryApplied || - declarativeArtifactRegistryApplied); + final bool validArtifactConfiguration = + documentationPresent && declarativeArtifactRegistryApplied; if (!validArtifactConfiguration) { printError('Failed Artifact Hub validation.'); @@ -269,14 +234,9 @@ plugins { 'The link to the Artifact Hub documentation is missing. Include the following in ' 'example root settings.gradle:\n// See $artifactHubDocumentationString for more info.'); } - if (artifactRegistryDefined || - artifactRegistryPluginApplied || - !declarativePluginBlockApplied) { - printError('Include the following in ' - 'example root settings.gradle:\n$exampleRootSettingsArtifactHubString'); - } else if (!declarativeArtifactRegistryApplied) { + if (!declarativeArtifactRegistryApplied) { printError('Include the following in ' - 'example root settings.gradle:\n$exampleSettingsArtifactHubStringGP'); + 'example root settings.gradle:\n$exampleSettingsArtifactHubString'); } } return validArtifactConfiguration; diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index 6c1a661e7c9c..d5f33767ccc3 100644 --- a/script/tool/test/gradle_check_command_test.dart +++ b/script/tool/test/gradle_check_command_test.dart @@ -169,39 +169,6 @@ ${warningsConfigured ? warningConfig : ''} '''); } - /// Writes a fake android/build.gradle file for an example [package] with the - /// given options. - void writeFakeExampleTopLevelSettingsGradle( - RepositoryPackage package, { - bool includeArtifactHub = true, - bool includeArtifactDocumentation = true, - }) { - final File settingsGradle = package - .platformDirectory(FlutterPlatform.android) - .childFile('settings.gradle'); - settingsGradle.createSync(recursive: true); - - settingsGradle.writeAsStringSync(''' -include ':app' - -def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() - -def plugins = new Properties() -def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') -if (pluginsFile.exists()) { - pluginsFile.withInputStream { stream -> plugins.load(stream) } -} - -plugins.each { name, path -> - def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() - include ":\$name" - project(":\$name").projectDir = pluginDirectory -} -${includeArtifactDocumentation ? '// See ${GradleCheckCommand.artifactHubDocumentationString} for more info.' : ''} -${includeArtifactHub ? GradleCheckCommand.exampleRootSettingsArtifactHubString : ''} -'''); - } - /// Writes a fake android/build.gradle file for an example [package] with the /// given options. void writeFakeExampleSettingsGradle( @@ -216,8 +183,7 @@ ${includeArtifactHub ? GradleCheckCommand.exampleRootSettingsArtifactHubString : /// String printed as a valid example of settings.gradle repository /// configuration without the artifact hub env variable. - /// GP stands for the gradle plugin method of flutter tooling inclusion. - const String exampleSettingsWithoutArtifactHubStringGP = ''' + const String exampleSettingsWithoutArtifactHubString = ''' plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" // ...other plugins @@ -244,7 +210,7 @@ pluginManagement { } ${includeArtifactDocumentation ? '// See ${GradleCheckCommand.artifactHubDocumentationString} for more info.' : ''} -${includeArtifactHub ? GradleCheckCommand.exampleSettingsArtifactHubStringGP : exampleSettingsWithoutArtifactHubStringGP} +${includeArtifactHub ? GradleCheckCommand.exampleSettingsArtifactHubString : exampleSettingsWithoutArtifactHubString} include ":app" '''); } @@ -310,36 +276,6 @@ dependencies { bool includeBuildArtifactHub = true, bool includeSettingsArtifactHub = true, bool includeSettingsDocumentationArtifactHub = true, - }) { - writeFakeExampleTopLevelBuildGradle( - package, - pluginName: pluginName, - warningsConfigured: warningsConfigured, - kotlinVersion: kotlinVersion, - includeArtifactHub: includeBuildArtifactHub, - ); - writeFakeExampleAppBuildGradle(package, - includeNamespace: includeNamespace, - commentNamespace: commentNamespace, - includeNameSpaceAsDeclaration: includeNameSpaceAsDeclaration); - writeFakeExampleTopLevelSettingsGradle( - package, - includeArtifactHub: includeSettingsArtifactHub, - includeArtifactDocumentation: includeSettingsDocumentationArtifactHub, - ); - } - - void writeFakeExampleBuildGradleGP( - RepositoryPackage package, { - required String pluginName, - bool includeNamespace = true, - bool commentNamespace = false, - bool includeNameSpaceAsDeclaration = false, - bool warningsConfigured = true, - String? kotlinVersion, - required bool includeBuildArtifactHub, - required bool includeSettingsArtifactHub, - required bool includeSettingsDocumentationArtifactHub, }) { writeFakeExampleTopLevelBuildGradle( package, @@ -827,7 +763,7 @@ dependencies { output, containsAllInOrder([ contains(GradleCheckCommand.exampleRootGradleArtifactHubString), - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString), + contains(GradleCheckCommand.exampleSettingsArtifactHubString), ]), ); }); @@ -859,11 +795,6 @@ dependencies { contains(GradleCheckCommand.exampleRootGradleArtifactHubString), ]), ); - expect( - output, - isNot( - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString)), - ); }); test('fails settings.gradle artifact hub check when missing', () async { @@ -890,7 +821,7 @@ dependencies { expect( output, containsAllInOrder([ - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString), + contains(GradleCheckCommand.exampleSettingsArtifactHubString), ]), ); expect( @@ -907,10 +838,12 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradleGP(example, + writeFakeExampleBuildGradles(example, pluginName: packageName, + // ignore: avoid_redundant_argument_values includeBuildArtifactHub: true, includeSettingsArtifactHub: false, + // ignore: avoid_redundant_argument_values includeSettingsDocumentationArtifactHub: true); writeFakeManifest(example, isApp: true); @@ -924,14 +857,9 @@ dependencies { expect( output, containsAllInOrder([ - contains(GradleCheckCommand.exampleSettingsArtifactHubStringGP), + contains(GradleCheckCommand.exampleSettingsArtifactHubString), ]), ); - expect( - output, - isNot( - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString)), - ); }); test('error message is printed when documentation link is missing', @@ -942,9 +870,11 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradleGP(example, + writeFakeExampleBuildGradles(example, pluginName: packageName, + // ignore: avoid_redundant_argument_values includeBuildArtifactHub: true, + // ignore: avoid_redundant_argument_values includeSettingsArtifactHub: true, includeSettingsDocumentationArtifactHub: false); writeFakeManifest(example, isApp: true); From cbd5cb8437473e852129a6b7a2dd70f9a74e6343 Mon Sep 17 00:00:00 2001 From: jesswrd Date: Fri, 20 Dec 2024 10:17:44 -0800 Subject: [PATCH 2/3] migrated all packages test project --- .../all_packages/android/app/build.gradle | 14 ++++----- .../all_packages/android/build.gradle | 11 ------- .../all_packages/android/settings.gradle | 31 ++++++++++++++----- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/.ci/legacy_project/all_packages/android/app/build.gradle b/.ci/legacy_project/all_packages/android/app/build.gradle index ce520a90d1f5..a73e2ac28cd7 100644 --- a/.ci/legacy_project/all_packages/android/app/build.gradle +++ b/.ci/legacy_project/all_packages/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "org.jetbrains.kotlin.android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,9 +22,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { namespace = "com.example.all_packages" compileSdkVersion 33 diff --git a/.ci/legacy_project/all_packages/android/build.gradle b/.ci/legacy_project/all_packages/android/build.gradle index 08cb0aa3de91..cf9fba7e06d0 100644 --- a/.ci/legacy_project/all_packages/android/build.gradle +++ b/.ci/legacy_project/all_packages/android/build.gradle @@ -1,14 +1,3 @@ -buildscript { - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.0.0' - } -} - allprojects { repositories { google() diff --git a/.ci/legacy_project/all_packages/android/settings.gradle b/.ci/legacy_project/all_packages/android/settings.gradle index 44e62bcf06ae..02d009e408b1 100644 --- a/.ci/legacy_project/all_packages/android/settings.gradle +++ b/.ci/legacy_project/all_packages/android/settings.gradle @@ -1,11 +1,26 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +// See https://github.com/flutter/flutter/blob/master/docs/ecosystem/Plugins-and-Packages-repository-structure.md#gradle-structure for more info. +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "7.0.0" apply false + id "org.jetbrains.kotlin.android" version "1.9.0" apply false +} + +include ":app" From e30495e4be7eb6ff54e65b5b5c5c6dbd9e54efdd Mon Sep 17 00:00:00 2001 From: jesswrd Date: Fri, 20 Dec 2024 17:00:58 -0800 Subject: [PATCH 3/3] removed removed operator and right operand --- .../lib/src/common/package_looping_command.dart | 4 ++-- .../lib/src/create_all_packages_app_command.dart | 4 ++-- script/tool/lib/src/pubspec_check_command.dart | 4 ++-- script/tool/lib/src/update_min_sdk_command.dart | 2 +- .../test/create_all_packages_app_command_test.dart | 2 +- script/tool/test/update_min_sdk_command_test.dart | 14 +++++++------- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/script/tool/lib/src/common/package_looping_command.dart b/script/tool/lib/src/common/package_looping_command.dart index 9dc32279e929..b9c7a87c067b 100644 --- a/script/tool/lib/src/common/package_looping_command.dart +++ b/script/tool/lib/src/common/package_looping_command.dart @@ -340,7 +340,7 @@ abstract class PackageLoopingCommand extends PackageCommand { if (minFlutterVersion != null) { final Pubspec pubspec = package.parsePubspec(); final VersionConstraint? flutterConstraint = - pubspec.environment?['flutter']; + pubspec.environment['flutter']; if (flutterConstraint != null && !flutterConstraint.allows(minFlutterVersion)) { return PackageResult.skip( @@ -350,7 +350,7 @@ abstract class PackageLoopingCommand extends PackageCommand { if (minDartVersion != null) { final Pubspec pubspec = package.parsePubspec(); - final VersionConstraint? dartConstraint = pubspec.environment?['sdk']; + final VersionConstraint? dartConstraint = pubspec.environment['sdk']; if (dartConstraint != null && !dartConstraint.allows(minDartVersion)) { return PackageResult.skip('Does not support Dart $minDartVersion'); } diff --git a/script/tool/lib/src/create_all_packages_app_command.dart b/script/tool/lib/src/create_all_packages_app_command.dart index ab6b5637dd7b..812c32133b25 100644 --- a/script/tool/lib/src/create_all_packages_app_command.dart +++ b/script/tool/lib/src/create_all_packages_app_command.dart @@ -277,7 +277,7 @@ dependencies {} final Pubspec originalPubspec = app.parsePubspec(); const String dartSdkKey = 'sdk'; final VersionConstraint dartSdkConstraint = - originalPubspec.environment?[dartSdkKey] ?? + originalPubspec.environment[dartSdkKey] ?? VersionConstraint.compatibleWith( Version.parse('3.0.0'), ); @@ -342,7 +342,7 @@ publish_to: none version: ${pubspec.version} -environment:${_pubspecMapString(pubspec.environment!)} +environment:${_pubspecMapString(pubspec.environment)} dependencies:${_pubspecMapString(pubspec.dependencies)} diff --git a/script/tool/lib/src/pubspec_check_command.dart b/script/tool/lib/src/pubspec_check_command.dart index 66ac470d8235..d8fafb1b2b62 100644 --- a/script/tool/lib/src/pubspec_check_command.dart +++ b/script/tool/lib/src/pubspec_check_command.dart @@ -488,9 +488,9 @@ class PubspecCheckCommand extends PackageLoopingCommand { } final Version? dartConstraintMin = - _minimumForConstraint(pubspec.environment?['sdk']); + _minimumForConstraint(pubspec.environment['sdk']); final Version? flutterConstraintMin = - _minimumForConstraint(pubspec.environment?['flutter']); + _minimumForConstraint(pubspec.environment['flutter']); // Validate the Flutter constraint, if any. if (flutterConstraintMin != null && minMinFlutterVersion != null) { diff --git a/script/tool/lib/src/update_min_sdk_command.dart b/script/tool/lib/src/update_min_sdk_command.dart index 429036a47ef9..603886ce94ad 100644 --- a/script/tool/lib/src/update_min_sdk_command.dart +++ b/script/tool/lib/src/update_min_sdk_command.dart @@ -87,7 +87,7 @@ class UpdateMinSdkCommand extends PackageLoopingCommand { /// Returns the given "environment" section's [key] constraint as a range, /// if the key is present and has a range. VersionRange? _sdkRange(Pubspec pubspec, String key) { - final VersionConstraint? constraint = pubspec.environment?[key]; + final VersionConstraint? constraint = pubspec.environment[key]; if (constraint is VersionRange) { return constraint; } diff --git a/script/tool/test/create_all_packages_app_command_test.dart b/script/tool/test/create_all_packages_app_command_test.dart index bed615f12b6f..b65371a1971a 100644 --- a/script/tool/test/create_all_packages_app_command_test.dart +++ b/script/tool/test/create_all_packages_app_command_test.dart @@ -356,7 +356,7 @@ android { final Pubspec generatedPubspec = command.app.parsePubspec(); const String dartSdkKey = 'sdk'; - expect(generatedPubspec.environment?[dartSdkKey].toString(), + expect(generatedPubspec.environment[dartSdkKey].toString(), existingSdkConstraint); }); diff --git a/script/tool/test/update_min_sdk_command_test.dart b/script/tool/test/update_min_sdk_command_test.dart index 52d69ccb7bd0..d9bc93f23105 100644 --- a/script/tool/test/update_min_sdk_command_test.dart +++ b/script/tool/test/update_min_sdk_command_test.dart @@ -50,7 +50,7 @@ void main() { ]); final String dartVersion = - package.parsePubspec().environment?['sdk'].toString() ?? ''; + package.parsePubspec().environment['sdk'].toString(); expect(dartVersion, '^3.1.0'); }); @@ -65,7 +65,7 @@ void main() { ]); final String dartVersion = - package.parsePubspec().environment?['sdk'].toString() ?? ''; + package.parsePubspec().environment['sdk'].toString(); expect(dartVersion, '^3.1.0'); }); @@ -80,7 +80,7 @@ void main() { ]); final String dartVersion = - package.parsePubspec().environment?['sdk'].toString() ?? ''; + package.parsePubspec().environment['sdk'].toString(); expect(dartVersion, '^3.2.0'); }); @@ -98,9 +98,9 @@ void main() { ]); final String dartVersion = - package.parsePubspec().environment?['sdk'].toString() ?? ''; + package.parsePubspec().environment['sdk'].toString(); final String flutterVersion = - package.parsePubspec().environment?['flutter'].toString() ?? ''; + package.parsePubspec().environment['flutter'].toString(); expect(dartVersion, '^3.1.0'); expect(flutterVersion, '>=3.13.0'); }); @@ -119,9 +119,9 @@ void main() { ]); final String dartVersion = - package.parsePubspec().environment?['sdk'].toString() ?? ''; + package.parsePubspec().environment['sdk'].toString(); final String flutterVersion = - package.parsePubspec().environment?['flutter'].toString() ?? ''; + package.parsePubspec().environment['flutter'].toString(); expect(dartVersion, '^3.2.0'); expect(flutterVersion, '>=3.16.0'); });