Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added regex for declarative way
  • Loading branch information
jesswrd committed Oct 21, 2024
commit 00c057989df3a584ca5172fcb22f7467f3ca4ea2
45 changes: 37 additions & 8 deletions script/tool/lib/src/gradle_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,47 @@ class GradleCheckCommand extends PackageLoopingCommand {
@visibleForTesting
static String exampleRootSettingsArtifactHubString = '''
// See $artifactHubDocumentationString for more info.
pluginManagement {
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"
''';

// GP stands for the gradle plugin method of flutter tooling inclusion.
@visibleForTesting
static String exampleRootSettingsArtifactHubStringGP = '''
// See $artifactHubDocumentationString for more info.
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
}()

includeBuild("\$flutterSdkPath/packages/flutter_tools/gradle")

repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
// ...other plugins
id "com.google.cloud.artifactregistry.gradle-plugin" version "2.2.1"
}
include ":app"
''';
''';

/// Validates that [gradleLines] reads and uses a artifiact hub repository
/// when ARTIFACT_HUB_REPOSITORY is set.
Expand All @@ -234,22 +253,32 @@ include ":app"
RepositoryPackage example, List<String> 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 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 artifactRegistryPluginAppliedGP = gradleLines
.any((String line) => artifactRegistryPluginApplyRegexGP.hasMatch(line));

final bool validArtifactConfiguration = documentationPresent &&
((artifactRegistryDefined && artifactRegistryPluginApplied) || artifactRegistryPluginAppliedGP);

if (!(documentationPresent &&
artifactRegistryPluginApplied)) {
if (!validArtifactConfiguration) {
printError('Failed Artifact Hub validation. Include the following in '
'example root settings.gradle:\n$exampleRootSettingsArtifactHubString');
}

return documentationPresent &&
artifactRegistryPluginApplied;
return validArtifactConfiguration;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the only thing is missing is the documentation, before it would print an example of what needed to be included that included the documentation, whereas now it would fail without any actionable message.

Copy link
Contributor Author

@jesswrd jesswrd Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried out only removing only the documentation, and it does include an error message. I have a check for documentationPresent when validArtifactConfiguration is deinfed, and check for !validArtifactConfiguration when an error should be printed. Could you further explain why it would fail?

}

/// Validates the top-level build.gradle for an example app (e.g.,
Expand Down