diff --git a/script/tool/lib/src/gradle_check_command.dart b/script/tool/lib/src/gradle_check_command.dart index 97f818015a28..1353b49a0e9c 100644 --- a/script/tool/lib/src/gradle_check_command.dart +++ b/script/tool/lib/src/gradle_check_command.dart @@ -198,23 +198,6 @@ 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. @@ -235,32 +218,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 - .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,12 +235,7 @@ 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'); } diff --git a/script/tool/test/gradle_check_command_test.dart b/script/tool/test/gradle_check_command_test.dart index 6c1a661e7c9c..61c750a7b1b8 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( @@ -299,7 +266,8 @@ dependencies { '''); } - void writeFakeExampleBuildGradles( + //TODO(jesswon): replace function with writeFakeExampleBuildGradles + void writeFakeExampleBuildGradleGP( RepositoryPackage package, { required String pluginName, bool includeNamespace = true, @@ -310,36 +278,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, @@ -481,7 +419,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, pluginName: pluginName); + writeFakeExampleBuildGradleGP(example, pluginName: pluginName); writeFakeManifest(example, isApp: true); final List output = @@ -595,7 +533,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: pluginName, includeNamespace: false); writeFakeManifest(example, isApp: true); @@ -625,7 +563,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, pluginName: pluginName); + writeFakeExampleBuildGradleGP(example, pluginName: pluginName); writeFakeManifest(example, isApp: true, packageName: 'wrong.package.name'); Error? commandError; @@ -672,7 +610,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: pluginName, includeNameSpaceAsDeclaration: true); writeFakeManifest(example, isApp: true); @@ -726,7 +664,7 @@ dependencies { writeFakePluginBuildGradle(plugin, includeLanguageVersion: true); writeFakeManifest(plugin); final RepositoryPackage example = plugin.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: pluginName, warningsConfigured: false); writeFakeManifest(example, isApp: true); @@ -755,7 +693,7 @@ dependencies { final RepositoryPackage plugin = createFakePackage(packageName, packagesDir); final RepositoryPackage example = plugin.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, warningsConfigured: false); writeFakeManifest(example, isApp: true); @@ -779,7 +717,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, // ignore: avoid_redundant_argument_values includeBuildArtifactHub: true, @@ -808,7 +746,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles( + writeFakeExampleBuildGradleGP( example, pluginName: packageName, includeBuildArtifactHub: false, @@ -827,7 +765,7 @@ dependencies { output, containsAllInOrder([ contains(GradleCheckCommand.exampleRootGradleArtifactHubString), - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString), + contains(GradleCheckCommand.exampleSettingsArtifactHubStringGP), ]), ); }); @@ -839,7 +777,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, includeBuildArtifactHub: false, // ignore: avoid_redundant_argument_values @@ -859,11 +797,6 @@ dependencies { contains(GradleCheckCommand.exampleRootGradleArtifactHubString), ]), ); - expect( - output, - isNot( - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString)), - ); }); test('fails settings.gradle artifact hub check when missing', () async { @@ -873,7 +806,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, // ignore: avoid_redundant_argument_values includeBuildArtifactHub: true, @@ -890,7 +823,7 @@ dependencies { expect( output, containsAllInOrder([ - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString), + contains(GradleCheckCommand.exampleSettingsArtifactHubStringGP), ]), ); expect( @@ -927,11 +860,6 @@ dependencies { contains(GradleCheckCommand.exampleSettingsArtifactHubStringGP), ]), ); - expect( - output, - isNot( - contains(GradleCheckCommand.exampleRootSettingsArtifactHubString)), - ); }); test('error message is printed when documentation link is missing', @@ -973,7 +901,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, pluginName: packageName); + writeFakeExampleBuildGradleGP(example, pluginName: packageName); writeFakeManifest(example, isApp: true); final List output = @@ -994,7 +922,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, kotlinVersion: minKotlinVersion.toString()); writeFakeManifest(example, isApp: true); @@ -1016,7 +944,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, kotlinVersion: '99.99.0'); writeFakeManifest(example, isApp: true); @@ -1038,7 +966,7 @@ dependencies { writeFakePluginBuildGradle(package, includeLanguageVersion: true); writeFakeManifest(package); final RepositoryPackage example = package.getExamples().first; - writeFakeExampleBuildGradles(example, + writeFakeExampleBuildGradleGP(example, pluginName: packageName, kotlinVersion: '1.6.21'); writeFakeManifest(example, isApp: true);