Skip to content

Commit

Permalink
Revert "Instrument add to app flows (flutter#33297)" (flutter#33449)
Browse files Browse the repository at this point in the history
This reverts commit faec4ca.
  • Loading branch information
jonahwilliams authored May 28, 2019
1 parent 2d9b158 commit 8e3e0a8
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 310 deletions.
7 changes: 1 addition & 6 deletions packages/flutter_tools/lib/src/commands/attach.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import '../resident_runner.dart';
import '../run_cold.dart';
import '../run_hot.dart';
import '../runner/flutter_command.dart';
import '../usage.dart';

/// A Flutter-command that attaches to applications that have been launched
/// without `flutter run`.
Expand Down Expand Up @@ -316,12 +315,8 @@ class AttachCommand extends FlutterCommand {
result = await runner.attach();
assert(result != null);
}
if (result == 0) {
flutterUsage.sendEvent('attach', 'success');
} else {
flutterUsage.sendEvent('attach', 'failure');
if (result != 0)
throwToolExit(null, exitCode: result);
}
} finally {
final List<ForwardedPort> ports = device.portForwarder.forwardedPorts.toList();
for (ForwardedPort port in ports) {
Expand Down
66 changes: 25 additions & 41 deletions packages/flutter_tools/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import '../globals.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
import '../template.dart';
import '../usage.dart';
import '../version.dart';

enum _ProjectType {
Expand Down Expand Up @@ -149,15 +148,6 @@ class CreateCommand extends FlutterCommand {
@override
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 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
Expand Down Expand Up @@ -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
Future<FlutterCommandResult> runCommand() async {
if (argResults['list-samples'] != null) {
Expand Down Expand Up @@ -323,7 +283,31 @@ class CreateCommand extends FlutterCommand {
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 generatePlugin = template == _ProjectType.plugin;
final bool generatePackage = template == _ProjectType.package;
Expand Down
53 changes: 11 additions & 42 deletions packages/flutter_tools/lib/src/commands/packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import '../base/os.dart';
import '../dart/pub.dart';
import '../project.dart';
import '../runner/flutter_command.dart';
import '../usage.dart';

class PackagesCommand extends FlutterCommand {
PackagesCommand() {
Expand Down Expand Up @@ -69,57 +68,27 @@ class PackagesGetCommand extends FlutterCommand {
return '${runner.executableName} pub $name [<target directory>]';
}

@override
Future<Map<String, String>> get usageValues async {
final Map<String, String> usageValues = <String, String>{};
final String workingDirectory = argResults.rest.length == 1 ? argResults.rest[0] : null;
final String target = findProjectRoot(workingDirectory);
if (target == null) {
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;
}
Future<void> _runPubGet (String directory) async {
await pubGet(context: PubContext.pubGet,
directory: directory,
upgrade: upgrade ,
offline: argResults['offline'],
checkLastModified: false,
);
}

@override
Future<FlutterCommandResult> runCommand() async {
if (argResults.rest.length > 1)
throwToolExit('Too many arguments.\n$usage');

final String workingDirectory = argResults.rest.length == 1 ? argResults.rest[0] : null;
final String target = findProjectRoot(workingDirectory);
final String target = findProjectRoot(
argResults.rest.length == 1 ? argResults.rest[0] : null
);
if (target == null) {
throwToolExit(
'Expected to find project root in '
'${ workingDirectory ?? "current working directory" }.'
'${ argResults.rest.length == 1 ? argResults.rest[0] : "current working directory" }.'
);
}

Expand Down
18 changes: 1 addition & 17 deletions packages/flutter_tools/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import '../run_cold.dart';
import '../run_hot.dart';
import '../runner/flutter_command.dart';
import '../tracing.dart';
import '../usage.dart';
import 'daemon.dart';

abstract class RunCommandBase extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
Expand Down Expand Up @@ -209,23 +208,8 @@ class RunCommand extends RunCommandBase {
final String deviceType = devices.length == 1
? getNameForTargetPlatform(await devices[0].targetPlatform)
: 'multiple';
final AndroidProject androidProject = FlutterProject.current().android;
final IosProject iosProject = FlutterProject.current().ios;
final List<String> hostLanguage = <String>[];

if (androidProject != null && androidProject.existsSync()) {
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(','),
};
return <String, String>{'cd3': '$isEmulator', 'cd4': deviceType};
}

@override
Expand Down
7 changes: 0 additions & 7 deletions packages/flutter_tools/lib/src/project.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ class AndroidProject {
final FlutterProject parent;

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*\$');

/// The Gradle root directory of the Android host app. This is the directory
Expand All @@ -420,12 +419,6 @@ class AndroidProject {
/// True if the parent Flutter project is a module.
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 {
return isUsingGradle
? fs.file(fs.path.join(hostAppGradleRoot.path, 'app', 'src', 'main', 'AndroidManifest.xml'))
Expand Down
13 changes: 0 additions & 13 deletions packages/flutter_tools/lib/src/usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ const String kEventReloadInvalidatedSourcesCount = 'cd11';
const String kEventReloadTransferTimeInMs = 'cd12';
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;

class Usage {
Expand Down
66 changes: 0 additions & 66 deletions packages/flutter_tools/test/commands/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:flutter_tools/src/version.dart';

import 'package:mockito/mockito.dart';
import 'package:process/process.dart';

import '../src/common.dart';
import '../src/context.dart';


const String frameworkRevision = '12345678';
const String frameworkChannel = 'omega';
final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
Expand Down Expand Up @@ -930,71 +927,8 @@ void main() {
HttpClientFactory: () =>
() => 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(
Directory dir,
List<String> createArgs,
Expand Down
Loading

0 comments on commit 8e3e0a8

Please sign in to comment.