Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {

dependencies {
implementation "androidx.annotation:annotation:1.9.1"
implementation 'com.google.android.gms:play-services-maps:18.2.0'
implementation 'com.google.android.gms:play-services-maps:19.2.0'
implementation 'com.google.maps.android:android-maps-utils:3.6.0'
androidTestImplementation 'androidx.test:runner:1.6.2'
androidTestImplementation 'androidx.test:rules:1.6.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2013 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 io.flutter.plugins.googlemaps;

abstract class Constants {

// Current package version.
public static final String FGM_PLUGIN_VERSION = "2.16.1";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.maps.MapsInitializer.Renderer;
import com.google.android.gms.maps.model.CameraPosition;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.platform.PlatformView;
Expand All @@ -31,6 +32,11 @@ public class GoogleMapFactory extends PlatformViewFactory {
@Override
@NonNull
public PlatformView create(@NonNull Context context, int id, @Nullable Object args) {
final boolean shouldInitializeRenderer = !googleMapInitializer.hasRendererInitializationStarted();
if (shouldInitializeRenderer) {
googleMapInitializer.initializeWithRendererRequest(Renderer.LATEST);
}

final Messages.PlatformMapViewCreationParams params =
Objects.requireNonNull((Messages.PlatformMapViewCreationParams) args);
final GoogleMapBuilder builder = new GoogleMapBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.maps.MapsApiSettings;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;
import io.flutter.plugin.common.BinaryMessenger;

/** GoogleMaps initializer used to initialize the Google Maps SDK with preferred settings. */
final class GoogleMapInitializer
implements OnMapsSdkInitializedCallback, Messages.MapsInitializerApi {

private final Context context;
private static Messages.Result<Messages.PlatformRendererType> initializationResult;
private boolean rendererInitialized = false;
private boolean rendererInitializationRequested = false;

GoogleMapInitializer(Context context, BinaryMessenger binaryMessenger) {
this.context = context;
Expand All @@ -41,14 +43,9 @@ public void initializeWithPreferredRenderer(
}
}

/**
* Initializes map renderer to with preferred renderer type.
*
* <p>This method is visible for testing purposes only and should never be used outside this
* class.
*/
@VisibleForTesting
/** Initializes map renderer with preferred renderer type. */
public void initializeWithRendererRequest(@Nullable MapsInitializer.Renderer renderer) {
rendererInitializationRequested = true;
MapsInitializer.initialize(context, renderer, this);
}

Expand All @@ -59,6 +56,12 @@ public void onMapsSdkInitialized(@NonNull MapsInitializer.Renderer renderer) {
if (initializationResult != null) {
switch (renderer) {
case LATEST:
// Set Android-specific Maps SDK attribution Id. This value should not be changed
// without discussing it first with code owners.
MapsApiSettings.addInternalUsageAttributionId(
context,
"gmp_flutter_googlemapsflutter_v" + Constants.FGM_PLUGIN_VERSION + "_android"
);
initializationResult.success(Messages.PlatformRendererType.LATEST);
break;
case LEGACY:
Expand All @@ -74,4 +77,9 @@ public void onMapsSdkInitialized(@NonNull MapsInitializer.Renderer renderer) {
initializationResult = null;
}
}

/** Returns true if renderer initialization has started or renderer has been initialized. */
boolean hasRendererInitializationStarted() {
return rendererInitialized || rendererInitializationRequested;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2013 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.

# This file is used to check that the version string in the Constants.java file is up to date and matches
# the version in pubspec.yaml.
checks:
- filepath: android/src/main/java/io/flutter/plugins/googlemaps/Constants.java
regexp: public static final String FGM_PLUGIN_VERSION = "([\.0-9]+)";
errorMessage: "Version string in Constants.java is not up to date. Please update it to the latest version."
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2013 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.

#ifndef FGMCONSTANTS_H
#define FGMCONSTANTS_H

// Google Maps Flutter Plugin version
#define FGM_PLUGIN_VERSION "2.15.2"

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
// found in the LICENSE file.

#import "FLTGoogleMapsPlugin.h"
#import "FGMConstants.h"

#pragma mark - GoogleMaps plugin implementation

@implementation FLTGoogleMapsPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FLTGoogleMapFactory *googleMapFactory = [[FLTGoogleMapFactory alloc] initWithRegistrar:registrar];

Class gmssClass = [GMSServices class];
SEL internalUsageAttributionIDSelector = @selector(addInternalUsageAttributionID:);

if ([gmssClass respondsToSelector:internalUsageAttributionIDSelector]) {
NSString *attributionId = [NSString stringWithFormat:@"gmp_flutter_googlemapsflutter_v%s_ios", FGM_PLUGIN_VERSION];
[GMSServices performSelector:internalUsageAttributionIDSelector withObject:attributionId];
}

[registrar registerViewFactory:googleMapFactory
withId:@"plugins.flutter.dev/google_maps_ios"
gestureRecognizersBlockingPolicy:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2013 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.

# This file is used to check that the version string in the FGMConstants.h file is up to date and matches
# the version in pubspec.yaml.
checks:
- filepath: ios/Classes/FGMConstants.h
regexp: define FGM_PLUGIN_VERSION "([\.0-9]+)"
errorMessage: "Version string in FGMConstants.h is not up to date. Please update it to the latest version."
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2013 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.

/// Google Maps Flutter Web plugin version.
const String fgmPluginVersion = '0.5.12';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2013 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.

# This file is used to check that the version string in the Constants.dart file is up to date and matches
# the version in pubspec.yaml.
checks:
- filepath: lib/src/constants.dart
regexp: const String fgmPluginVersion = '([\.0-9]+)';
errorMessage: "Version string in constants.dart is not up to date. Please update it to the latest version."
4 changes: 4 additions & 0 deletions script/tool/lib/src/common/repository_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class RepositoryPackage {
File get prePublishScript =>
directory.childDirectory('tool').childFile('pre_publish.dart');

/// The verion_check.yaml file that is used to check the version of
/// the package present in the platform implementation.
File get versionCheckFile => directory.childFile('version_check.yaml');

/// Returns the directory containing support for [platform].
Directory platformDirectory(FlutterPlatform platform) {
late final String directoryName;
Expand Down
130 changes: 130 additions & 0 deletions script/tool/lib/src/version_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';

import 'common/git_version_finder.dart';
import 'common/output_utils.dart';
Expand Down Expand Up @@ -223,6 +224,15 @@ class VersionCheckCommand extends PackageLoopingCommand {
errors.add('CHANGELOG.md failed validation.');
}

final YamlMap? versionCheckYaml = tryParseVersionCheckYaml(package);
if (!validateVersionCheckYamlVersion(
versionCheckYaml: versionCheckYaml,
version: pubspec.version,
package: package,
)) {
errors.add('Invalid version_check.yaml.');
}

// If there are no other issues, make sure that there isn't a missing
// change to the version and/or CHANGELOG.
if (getBoolArg(_checkForMissingChanges) &&
Expand Down Expand Up @@ -583,4 +593,124 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.

return null;
}

@visibleForTesting
YamlMap? tryParseVersionCheckYaml(RepositoryPackage package) {
final File versionCheckFile = package.directory.childFile(
'version_check.yaml',
);
if (!versionCheckFile.existsSync()) {
return null;
}

try {
final String content = versionCheckFile.readAsStringSync();
return loadYaml(content) as YamlMap;
} catch (e) {
printError('Invalid version_check.yaml format: $e');
return null;
}
}

/// Validates versions using the version_check.yaml file.
///
/// This checks that the version in the specified file matches the version
/// in the pubspec.yaml file.
///
/// version_check.yaml should contain a list of checks, each with the
/// following fields:
/// - filepath: The path to the file to check (could be platform-specific,
/// e.g. .java on Android, .h on iOS etc).
/// - regexp: The regex pattern to match the version string. Group 1 of the
/// regex should contain the version string (e.g. 1.0.4).
/// - errorMessage: The error message to display if the version does
/// not match.
///
/// No validation is performed if the version_check.yaml file does not exist.
///
/// Returns true if the validation passes, false otherwise.
@visibleForTesting
bool validateVersionCheckYamlVersion({
required YamlMap? versionCheckYaml,
required Version? version,
required RepositoryPackage package,
}) {
// Skip validation if the yaml file doesn't exist.
if (versionCheckYaml == null || version == null) {
return true;
}

final YamlList? checks = versionCheckYaml['checks'] as YamlList?;
if (checks == null) {
printError('Invalid version_check.yaml: Missing checks.');
return false;
}

bool result = true;
for (final YamlNode entry in checks.nodes) {
final YamlMap node = entry as YamlMap;
final String? filepath = node['filepath'] as String?;
final String? regex = node['regexp'] as String?;
final String? errorMessage = node['errorMessage'] as String?;

if (filepath == null || filepath.isEmpty) {
printError('Invalid version_check.yaml: Missing filepath.');
result = false;
continue;
}

if (regex == null || regex.isEmpty) {
printError('Invalid version_check.yaml: Missing regexp.');
result = false;
continue;
}

if (errorMessage == null || filepath.isEmpty) {
printError('Invalid version_check.yaml: Missing errorMessage.');
result = false;
continue;
}

final File targetFile = package.directory.childFile(filepath);
if (!targetFile.existsSync()) {
printError(
'File "$filepath" specified in version_check.yaml does not exist.',
);
result = false;
continue;
}

if (!targetFile.absolute.path.startsWith(package.directory.path)) {
printError(
'File path "$filepath" in version_check.yaml targets outside the package directory.',
);
result = false;
continue;
}

final RegExp versionRegex = RegExp(regex);
final String fileContent = targetFile.readAsStringSync();
final Match? match = versionRegex.firstMatch(fileContent);

if (match == null || match.groupCount < 1) {
printError(
'No version string found in "$filepath" using the provided regex.',
);
result = false;
continue;
}

final String foundVersion = match.group(1)!;
if (foundVersion != version.toString()) {
printError('Version mismatch in "$filepath":\n'
'Expected: $version\n'
'Found: $foundVersion\n'
'Error message: $errorMessage');
result = false;
continue;
}
}

return result;
}
}
Loading