Unverified Commit 8e3e0a89 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Revert "Instrument add to app flows (#33297)" (#33449)

This reverts commit faec4ca3.
parent 2d9b158f
...@@ -26,7 +26,6 @@ import '../resident_runner.dart'; ...@@ -26,7 +26,6 @@ import '../resident_runner.dart';
import '../run_cold.dart'; import '../run_cold.dart';
import '../run_hot.dart'; import '../run_hot.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../usage.dart';
/// A Flutter-command that attaches to applications that have been launched /// A Flutter-command that attaches to applications that have been launched
/// without `flutter run`. /// without `flutter run`.
...@@ -316,12 +315,8 @@ class AttachCommand extends FlutterCommand { ...@@ -316,12 +315,8 @@ class AttachCommand extends FlutterCommand {
result = await runner.attach(); result = await runner.attach();
assert(result != null); assert(result != null);
} }
if (result == 0) { if (result != 0)
flutterUsage.sendEvent('attach', 'success');
} else {
flutterUsage.sendEvent('attach', 'failure');
throwToolExit(null, exitCode: result); throwToolExit(null, exitCode: result);
}
} finally { } finally {
final List<ForwardedPort> ports = device.portForwarder.forwardedPorts.toList(); final List<ForwardedPort> ports = device.portForwarder.forwardedPorts.toList();
for (ForwardedPort port in ports) { for (ForwardedPort port in ports) {
......
...@@ -24,7 +24,6 @@ import '../globals.dart'; ...@@ -24,7 +24,6 @@ import '../globals.dart';
import '../project.dart'; import '../project.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../template.dart'; import '../template.dart';
import '../usage.dart';
import '../version.dart'; import '../version.dart';
enum _ProjectType { enum _ProjectType {
...@@ -149,15 +148,6 @@ class CreateCommand extends FlutterCommand { ...@@ -149,15 +148,6 @@ class CreateCommand extends FlutterCommand {
@override @override
String get invocation => '${runner.executableName} $name <output directory>'; String get invocation => '${runner.executableName} $name <output directory>';
@override
Future<Map<String, String>> get usageValues async {
return <String, String>{
kCommandCreateProjectType: argResults['template'],
kCommandCreateAndroidLanguage: argResults['android-language'],
kCommandCreateIosLanguage: argResults['ios-language'],
};
}
// If it has a .metadata file with the project_type in it, use that. // If it has a .metadata file with the project_type in it, use that.
// If it has an android dir and an android/app dir, it's a legacy app // If it has an android dir and an android/app dir, it's a legacy app
// If it has an ios dir and an ios/Flutter dir, it's a legacy app // If it has an ios dir and an ios/Flutter dir, it's a legacy app
...@@ -238,36 +228,6 @@ class CreateCommand extends FlutterCommand { ...@@ -238,36 +228,6 @@ class CreateCommand extends FlutterCommand {
} }
} }
_ProjectType _getProjectType(Directory projectDir) {
_ProjectType template;
_ProjectType detectedProjectType;
final bool metadataExists = projectDir.absolute.childFile('.metadata').existsSync();
if (argResults['template'] != null) {
template = _stringToProjectType(argResults['template']);
} else {
// If the project directory exists and isn't empty, then try to determine the template
// type from the project directory.
if (projectDir.existsSync() && projectDir.listSync().isNotEmpty) {
detectedProjectType = _determineTemplateType(projectDir);
if (detectedProjectType == null && metadataExists) {
// We can only be definitive that this is the wrong type if the .metadata file
// exists and contains a type that we don't understand, or doesn't contain a type.
throwToolExit('Sorry, unable to detect the type of project to recreate. '
'Try creating a fresh project and migrating your existing code to '
'the new project manually.');
}
}
}
template ??= detectedProjectType ?? _ProjectType.app;
if (detectedProjectType != null && template != detectedProjectType && metadataExists) {
// We can only be definitive that this is the wrong type if the .metadata file
// exists and contains a type that doesn't match.
throwToolExit("The requested template type '${getEnumName(template)}' doesn't match the "
"existing template type of '${getEnumName(detectedProjectType)}'.");
}
return template;
}
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
if (argResults['list-samples'] != null) { if (argResults['list-samples'] != null) {
...@@ -323,7 +283,31 @@ class CreateCommand extends FlutterCommand { ...@@ -323,7 +283,31 @@ class CreateCommand extends FlutterCommand {
sampleCode = await _fetchSampleFromServer(argResults['sample']); sampleCode = await _fetchSampleFromServer(argResults['sample']);
} }
final _ProjectType template = _getProjectType(projectDir); _ProjectType template;
_ProjectType detectedProjectType;
final bool metadataExists = projectDir.absolute.childFile('.metadata').existsSync();
if (argResults['template'] != null) {
template = _stringToProjectType(argResults['template']);
} else {
if (projectDir.existsSync() && projectDir.listSync().isNotEmpty) {
detectedProjectType = _determineTemplateType(projectDir);
if (detectedProjectType == null && metadataExists) {
// We can only be definitive that this is the wrong type if the .metadata file
// exists and contains a type that we don't understand, or doesn't contain a type.
throwToolExit('Sorry, unable to detect the type of project to recreate. '
'Try creating a fresh project and migrating your existing code to '
'the new project manually.');
}
}
}
template ??= detectedProjectType ?? _ProjectType.app;
if (detectedProjectType != null && template != detectedProjectType && metadataExists) {
// We can only be definitive that this is the wrong type if the .metadata file
// exists and contains a type that doesn't match.
throwToolExit("The requested template type '${getEnumName(template)}' doesn't match the "
"existing template type of '${getEnumName(detectedProjectType)}'.");
}
final bool generateModule = template == _ProjectType.module; final bool generateModule = template == _ProjectType.module;
final bool generatePlugin = template == _ProjectType.plugin; final bool generatePlugin = template == _ProjectType.plugin;
final bool generatePackage = template == _ProjectType.package; final bool generatePackage = template == _ProjectType.package;
......
...@@ -9,7 +9,6 @@ import '../base/os.dart'; ...@@ -9,7 +9,6 @@ import '../base/os.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../project.dart'; import '../project.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../usage.dart';
class PackagesCommand extends FlutterCommand { class PackagesCommand extends FlutterCommand {
PackagesCommand() { PackagesCommand() {
...@@ -69,44 +68,13 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -69,44 +68,13 @@ class PackagesGetCommand extends FlutterCommand {
return '${runner.executableName} pub $name [<target directory>]'; return '${runner.executableName} pub $name [<target directory>]';
} }
@override Future<void> _runPubGet (String directory) async {
Future<Map<String, String>> get usageValues async { await pubGet(context: PubContext.pubGet,
final Map<String, String> usageValues = <String, String>{}; directory: directory,
final String workingDirectory = argResults.rest.length == 1 ? argResults.rest[0] : null; upgrade: upgrade ,
final String target = findProjectRoot(workingDirectory); offline: argResults['offline'],
if (target == null) { checkLastModified: false,
return usageValues; );
}
final FlutterProject rootProject = FlutterProject.fromPath(target);
final bool hasPlugins = await rootProject.flutterPluginsFile.exists();
if (hasPlugins) {
final int numberOfPlugins = (await rootProject.flutterPluginsFile.readAsLines()).length;
usageValues[kCommandPackagesNumberPlugins] = '$numberOfPlugins';
} else {
usageValues[kCommandPackagesNumberPlugins] = '0';
}
usageValues[kCommandPackagesProjectModule] = '${rootProject.isModule}';
return usageValues;
}
Future<void> _runPubGet(String directory) async {
final Stopwatch pubGetTimer = Stopwatch()..start();
try {
await pubGet(context: PubContext.pubGet,
directory: directory,
upgrade: upgrade ,
offline: argResults['offline'],
checkLastModified: false,
);
pubGetTimer.stop();
flutterUsage.sendEvent('packages-pub-get', 'success');
flutterUsage.sendTiming('packages-pub-get', 'success', pubGetTimer.elapsed);
} catch (_) {
pubGetTimer.stop();
flutterUsage.sendEvent('packages-pub-get', 'failure');
flutterUsage.sendTiming('packages-pub-get', 'failure', pubGetTimer.elapsed);
rethrow;
}
} }
@override @override
...@@ -114,12 +82,13 @@ class PackagesGetCommand extends FlutterCommand { ...@@ -114,12 +82,13 @@ class PackagesGetCommand extends FlutterCommand {
if (argResults.rest.length > 1) if (argResults.rest.length > 1)
throwToolExit('Too many arguments.\n$usage'); throwToolExit('Too many arguments.\n$usage');
final String workingDirectory = argResults.rest.length == 1 ? argResults.rest[0] : null; final String target = findProjectRoot(
final String target = findProjectRoot(workingDirectory); argResults.rest.length == 1 ? argResults.rest[0] : null
);
if (target == null) { if (target == null) {
throwToolExit( throwToolExit(
'Expected to find project root in ' 'Expected to find project root in '
'${ workingDirectory ?? "current working directory" }.' '${ argResults.rest.length == 1 ? argResults.rest[0] : "current working directory" }.'
); );
} }
......
...@@ -19,7 +19,6 @@ import '../run_cold.dart'; ...@@ -19,7 +19,6 @@ import '../run_cold.dart';
import '../run_hot.dart'; import '../run_hot.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../tracing.dart'; import '../tracing.dart';
import '../usage.dart';
import 'daemon.dart'; import 'daemon.dart';
abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopmentArtifacts { abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
...@@ -209,23 +208,8 @@ class RunCommand extends RunCommandBase { ...@@ -209,23 +208,8 @@ class RunCommand extends RunCommandBase {
final String deviceType = devices.length == 1 final String deviceType = devices.length == 1
? getNameForTargetPlatform(await devices[0].targetPlatform) ? getNameForTargetPlatform(await devices[0].targetPlatform)
: 'multiple'; : 'multiple';
final AndroidProject androidProject = FlutterProject.current().android;
final IosProject iosProject = FlutterProject.current().ios;
final List<String> hostLanguage = <String>[];
if (androidProject != null && androidProject.existsSync()) { return <String, String>{'cd3': '$isEmulator', 'cd4': deviceType};
hostLanguage.add(androidProject.isKotlin ? 'kotlin' : 'java');
}
if (iosProject != null && iosProject.exists) {
hostLanguage.add(iosProject.isSwift ? 'swift' : 'objc');
}
return <String, String>{
kCommandRunIsEmulator: '$isEmulator',
kCommandRunTargetName: deviceType,
kCommandRunProjectModule: '${FlutterProject.current().isModule}',
kCommandRunProjectHostLanguage: hostLanguage.join(','),
};
} }
@override @override
......
...@@ -397,7 +397,6 @@ class AndroidProject { ...@@ -397,7 +397,6 @@ class AndroidProject {
final FlutterProject parent; final FlutterProject parent;
static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s+[\'\"](.*)[\'\"]\\s*\$'); static final RegExp _applicationIdPattern = RegExp('^\\s*applicationId\\s+[\'\"](.*)[\'\"]\\s*\$');
static final RegExp _kotlinPluginPattern = RegExp('^\\s*apply plugin\:\\s+[\'\"]kotlin-android[\'\"]\\s*\$');
static final RegExp _groupPattern = RegExp('^\\s*group\\s+[\'\"](.*)[\'\"]\\s*\$'); static final RegExp _groupPattern = RegExp('^\\s*group\\s+[\'\"](.*)[\'\"]\\s*\$');
/// The Gradle root directory of the Android host app. This is the directory /// The Gradle root directory of the Android host app. This is the directory
...@@ -420,12 +419,6 @@ class AndroidProject { ...@@ -420,12 +419,6 @@ class AndroidProject {
/// True if the parent Flutter project is a module. /// True if the parent Flutter project is a module.
bool get isModule => parent.isModule; bool get isModule => parent.isModule;
/// True, if the app project is using Kotlin.
bool get isKotlin {
final File gradleFile = hostAppGradleRoot.childDirectory('app').childFile('build.gradle');
return _firstMatchInFile(gradleFile, _kotlinPluginPattern) != null;
}
File get appManifestFile { File get appManifestFile {
return isUsingGradle return isUsingGradle
? fs.file(fs.path.join(hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml')) ? fs.file(fs.path.join(hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml'))
......
...@@ -26,19 +26,6 @@ const String kEventReloadInvalidatedSourcesCount = 'cd11'; ...@@ -26,19 +26,6 @@ const String kEventReloadInvalidatedSourcesCount = 'cd11';
const String kEventReloadTransferTimeInMs = 'cd12'; const String kEventReloadTransferTimeInMs = 'cd12';
const String kEventReloadOverallTimeInMs = 'cd13'; const String kEventReloadOverallTimeInMs = 'cd13';
const String kCommandRunIsEmulator = 'cd3';
const String kCommandRunTargetName = 'cd4';
const String kCommandRunProjectType = 'cd14';
const String kCommandRunProjectHostLanguage = 'cd15';
const String kCommandRunProjectModule = 'cd18';
const String kCommandCreateAndroidLanguage = 'cd16';
const String kCommandCreateIosLanguage = 'cd17';
const String kCommandCreateProjectType = 'cd19';
const String kCommandPackagesNumberPlugins = 'cd20';
const String kCommandPackagesProjectModule = 'cd21';
Usage get flutterUsage => Usage.instance; Usage get flutterUsage => Usage.instance;
class Usage { class Usage {
......
...@@ -14,16 +14,13 @@ import 'package:flutter_tools/src/cache.dart'; ...@@ -14,16 +14,13 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart'; import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/dart/sdk.dart'; import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
const String frameworkRevision = '12345678'; const String frameworkRevision = '12345678';
const String frameworkChannel = 'omega'; const String frameworkChannel = 'omega';
final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false; final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
...@@ -930,71 +927,8 @@ void main() { ...@@ -930,71 +927,8 @@ void main() {
HttpClientFactory: () => HttpClientFactory: () =>
() => MockHttpClient(404, result: 'not found'), () => MockHttpClient(404, result: 'not found'),
}); });
group('usageValues', () {
testUsingContext('set template type as usage value', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--template=module', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'module'));
await runner.run(<String>['create', '--no-pub', '--template=app', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'app'));
await runner.run(<String>['create', '--no-pub', '--template=package', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'package'));
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'plugin'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('set iOS host language type as usage value', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--template=app', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateIosLanguage, 'objc'));
await runner.run(<String>[
'create',
'--no-pub',
'--template=app',
'--ios-language=swift',
projectDir.path,
]);
expect(await command.usageValues, containsPair(kCommandCreateIosLanguage, 'swift'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('set Android host language type as usage value', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--template=app', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateAndroidLanguage, 'java'));
await runner.run(<String>[
'create',
'--no-pub',
'--template=app',
'--android-language=kotlin',
projectDir.path,
]);
expect(await command.usageValues, containsPair(kCommandCreateAndroidLanguage, 'kotlin'));
}, timeout: allowForCreateFlutterProject);
});
} }
Future<void> _createProject( Future<void> _createProject(
Directory dir, Directory dir,
List<String> createArgs, List<String> createArgs,
......
...@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/io.dart'; ...@@ -10,7 +10,6 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/utils.dart'; import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/packages.dart'; import 'package:flutter_tools/src/commands/packages.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -58,7 +57,7 @@ void main() { ...@@ -58,7 +57,7 @@ void main() {
return projectPath; return projectPath;
} }
Future<PackagesCommand> runCommandIn(String projectPath, String verb, { List<String> args }) async { Future<void> runCommandIn(String projectPath, String verb, { List<String> args }) async {
final PackagesCommand command = PackagesCommand(); final PackagesCommand command = PackagesCommand();
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
...@@ -68,7 +67,6 @@ void main() { ...@@ -68,7 +67,6 @@ void main() {
commandArgs.add(projectPath); commandArgs.add(projectPath);
await runner.run(commandArgs); await runner.run(commandArgs);
return command;
} }
void expectExists(String projectPath, String relPath) { void expectExists(String projectPath, String relPath) {
...@@ -219,39 +217,6 @@ void main() { ...@@ -219,39 +217,6 @@ void main() {
expectZeroPluginsInjected(projectPath); expectZeroPluginsInjected(projectPath);
}, timeout: allowForCreateFlutterProject); }, timeout: allowForCreateFlutterProject);
testUsingContext('set the number of plugins as usage value', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);
removeGeneratedFiles(projectPath);
final PackagesCommand command = await runCommandIn(projectPath, 'get');
final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand;
expect(await getCommand.usageValues, containsPair(kCommandPackagesNumberPlugins, '0'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('indicate that the project is not a module in usage value', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub']);
removeGeneratedFiles(projectPath);
final PackagesCommand command = await runCommandIn(projectPath, 'get');
final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand;
expect(await getCommand.usageValues, containsPair(kCommandPackagesProjectModule, 'false'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('indicate that the project is a module in usage value', () async {
final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']);
removeGeneratedFiles(projectPath);
final PackagesCommand command = await runCommandIn(projectPath, 'get');
final PackagesGetCommand getCommand = command.subcommands['get'] as PackagesGetCommand;
expect(await getCommand.usageValues, containsPair(kCommandPackagesProjectModule, 'true'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('upgrade fetches packages', () async { testUsingContext('upgrade fetches packages', () async {
final String projectPath = await createProject(tempDir, final String projectPath = await createProject(tempDir,
arguments: <String>['--no-pub', '--template=module']); arguments: <String>['--no-pub', '--template=module']);
......
...@@ -227,41 +227,6 @@ void main() { ...@@ -227,41 +227,6 @@ void main() {
}); });
}); });
group('language', () {
MockXcodeProjectInterpreter mockXcodeProjectInterpreter;
MemoryFileSystem fs;
setUp(() {
fs = MemoryFileSystem();
mockXcodeProjectInterpreter = MockXcodeProjectInterpreter();
});
testInMemory('default host app language', () async {
final FlutterProject project = await someProject();
expect(project.ios.isSwift, isFalse);
expect(project.android.isKotlin, isFalse);
});
testUsingContext('swift and kotlin host app language', () async {
final FlutterProject project = await someProject();
when(mockXcodeProjectInterpreter.getBuildSettings(any, any)).thenReturn(<String, String>{
'SWIFT_VERSION': '3.0',
});
addAndroidGradleFile(project.directory,
gradleFileContent: () {
return '''
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
''';
});
expect(project.ios.isSwift, isTrue);
expect(project.android.isKotlin, isTrue);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
XcodeProjectInterpreter: () => mockXcodeProjectInterpreter,
});
});
group('product bundle identifier', () { group('product bundle identifier', () {
MemoryFileSystem fs; MemoryFileSystem fs;
MockIOSWorkflow mockIOSWorkflow; MockIOSWorkflow mockIOSWorkflow;
...@@ -286,9 +251,7 @@ apply plugin: 'kotlin-android' ...@@ -286,9 +251,7 @@ apply plugin: 'kotlin-android'
}); });
testWithMocks('from pbxproj file, if no plist', () async { testWithMocks('from pbxproj file, if no plist', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject');
return projectFileWithBundleId('io.flutter.someProject');
});
expect(project.ios.productBundleIdentifier, 'io.flutter.someProject'); expect(project.ios.productBundleIdentifier, 'io.flutter.someProject');
}); });
testWithMocks('from plist, if no variables', () async { testWithMocks('from plist, if no variables', () async {
...@@ -298,9 +261,7 @@ apply plugin: 'kotlin-android' ...@@ -298,9 +261,7 @@ apply plugin: 'kotlin-android'
}); });
testWithMocks('from pbxproj and plist, if default variable', () async { testWithMocks('from pbxproj and plist, if default variable', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject');
return projectFileWithBundleId('io.flutter.someProject');
});
when(mockIOSWorkflow.getPlistValueFromFile(any, any)).thenReturn('\$(PRODUCT_BUNDLE_IDENTIFIER)'); when(mockIOSWorkflow.getPlistValueFromFile(any, any)).thenReturn('\$(PRODUCT_BUNDLE_IDENTIFIER)');
expect(project.ios.productBundleIdentifier, 'io.flutter.someProject'); expect(project.ios.productBundleIdentifier, 'io.flutter.someProject');
}); });
...@@ -315,23 +276,17 @@ apply plugin: 'kotlin-android' ...@@ -315,23 +276,17 @@ apply plugin: 'kotlin-android'
}); });
testWithMocks('empty surrounded by quotes', () async { testWithMocks('empty surrounded by quotes', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, '', qualifier: '"');
return projectFileWithBundleId('', qualifier: '"');
});
expect(project.ios.productBundleIdentifier, ''); expect(project.ios.productBundleIdentifier, '');
}); });
testWithMocks('surrounded by double quotes', () async { testWithMocks('surrounded by double quotes', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject', qualifier: '"');
return projectFileWithBundleId('io.flutter.someProject', qualifier: '"');
});
expect(project.ios.productBundleIdentifier, 'io.flutter.someProject'); expect(project.ios.productBundleIdentifier, 'io.flutter.someProject');
}); });
testWithMocks('surrounded by single quotes', () async { testWithMocks('surrounded by single quotes', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject', qualifier: '\'');
return projectFileWithBundleId('io.flutter.someProject', qualifier: '\'');
});
expect(project.ios.productBundleIdentifier, 'io.flutter.someProject'); expect(project.ios.productBundleIdentifier, 'io.flutter.someProject');
}); });
}); });
...@@ -348,32 +303,22 @@ apply plugin: 'kotlin-android' ...@@ -348,32 +303,22 @@ apply plugin: 'kotlin-android'
}); });
testInMemory('is populated from iOS bundle identifier', () async { testInMemory('is populated from iOS bundle identifier', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject');
return projectFileWithBundleId('io.flutter.someProject', qualifier: '\'');
});
expect(project.organizationNames, <String>['io.flutter']); expect(project.organizationNames, <String>['io.flutter']);
}); });
testInMemory('is populated from Android application ID', () async { testInMemory('is populated from Android application ID', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addAndroidGradleFile(project.directory, addAndroidWithApplicationId(project.directory, 'io.flutter.someproject');
gradleFileContent: () {
return gradleFileWithApplicationId('io.flutter.someproject');
});
expect(project.organizationNames, <String>['io.flutter']); expect(project.organizationNames, <String>['io.flutter']);
}); });
testInMemory('is populated from iOS bundle identifier in plugin example', () async { testInMemory('is populated from iOS bundle identifier in plugin example', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.example.directory, projectFileContent: () { addIosWithBundleId(project.example.directory, 'io.flutter.someProject');
return projectFileWithBundleId('io.flutter.someProject', qualifier: '\'');
});
expect(project.organizationNames, <String>['io.flutter']); expect(project.organizationNames, <String>['io.flutter']);
}); });
testInMemory('is populated from Android application ID in plugin example', () async { testInMemory('is populated from Android application ID in plugin example', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addAndroidGradleFile(project.example.directory, addAndroidWithApplicationId(project.example.directory, 'io.flutter.someproject');
gradleFileContent: () {
return gradleFileWithApplicationId('io.flutter.someproject');
});
expect(project.organizationNames, <String>['io.flutter']); expect(project.organizationNames, <String>['io.flutter']);
}); });
testInMemory('is populated from Android group in plugin', () async { testInMemory('is populated from Android group in plugin', () async {
...@@ -383,24 +328,14 @@ apply plugin: 'kotlin-android' ...@@ -383,24 +328,14 @@ apply plugin: 'kotlin-android'
}); });
testInMemory('is singleton, if sources agree', () async { testInMemory('is singleton, if sources agree', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject');
return projectFileWithBundleId('io.flutter.someProject'); addAndroidWithApplicationId(project.directory, 'io.flutter.someproject');
});
addAndroidGradleFile(project.directory,
gradleFileContent: () {
return gradleFileWithApplicationId('io.flutter.someproject');
});
expect(project.organizationNames, <String>['io.flutter']); expect(project.organizationNames, <String>['io.flutter']);
}); });
testInMemory('is non-singleton, if sources disagree', () async { testInMemory('is non-singleton, if sources disagree', () async {
final FlutterProject project = await someProject(); final FlutterProject project = await someProject();
addIosProjectFile(project.directory, projectFileContent: () { addIosWithBundleId(project.directory, 'io.flutter.someProject');
return projectFileWithBundleId('io.flutter.someProject'); addAndroidWithApplicationId(project.directory, 'io.clutter.someproject');
});
addAndroidGradleFile(project.directory,
gradleFileContent: () {
return gradleFileWithApplicationId('io.clutter.someproject');
});
expect( expect(
project.organizationNames, project.organizationNames,
<String>['io.flutter', 'io.clutter'], <String>['io.flutter', 'io.clutter'],
...@@ -540,22 +475,22 @@ void expectNotExists(FileSystemEntity entity) { ...@@ -540,22 +475,22 @@ void expectNotExists(FileSystemEntity entity) {
expect(entity.existsSync(), isFalse); expect(entity.existsSync(), isFalse);
} }
void addIosProjectFile(Directory directory, {String projectFileContent()}) { void addIosWithBundleId(Directory directory, String id, {String qualifier}) {
directory directory
.childDirectory('ios') .childDirectory('ios')
.childDirectory('Runner.xcodeproj') .childDirectory('Runner.xcodeproj')
.childFile('project.pbxproj') .childFile('project.pbxproj')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(projectFileContent()); ..writeAsStringSync(projectFileWithBundleId(id, qualifier: qualifier));
} }
void addAndroidGradleFile(Directory directory, { String gradleFileContent() }) { void addAndroidWithApplicationId(Directory directory, String id) {
directory directory
.childDirectory('android') .childDirectory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync(gradleFileContent()); ..writeAsStringSync(gradleFileWithApplicationId(id));
} }
void addAndroidWithGroup(Directory directory, String id) { void addAndroidWithGroup(Directory directory, String id) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment